Adding more tests for the typechecking phase
This commit is contained in:
@ -1,3 +1,12 @@
|
||||
Error absent assignment program: error
|
||||
Error wrong arity program 1: error
|
||||
Error wrong arity program 2: error
|
||||
Error wrong return type program: error
|
||||
Error wrong specification program: error
|
||||
Error wrong input type program: error
|
||||
Error not a function program: error
|
||||
Error if branches with different types program: error
|
||||
Error if guard is not a boolean program: error
|
||||
Identity program: true
|
||||
Constant program: true
|
||||
Partial application of function program: true
|
||||
|
||||
@ -1,5 +1,153 @@
|
||||
open Lang.MiniFun
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error absent assignment program *)
|
||||
|
||||
let program =
|
||||
Function
|
||||
(["a"],
|
||||
FunctionType ([IntegerType], IntegerType),
|
||||
(Variable "x")
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error absent assignment program: %b\n" (typecheck program)
|
||||
with AbsentAssignment _ ->
|
||||
Printf.printf "Error absent assignment program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong arity program *)
|
||||
|
||||
let program =
|
||||
Function
|
||||
(["a"],
|
||||
FunctionType ([IntegerType; IntegerType], IntegerType),
|
||||
(Variable "a")
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong arity program 1: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong arity program 1: error\n"
|
||||
|
||||
let program =
|
||||
LetFun
|
||||
("f",
|
||||
["a"; "b"],
|
||||
FunctionType ([IntegerType; IntegerType], IntegerType),
|
||||
(Variable "a"),
|
||||
Function (["x"], FunctionType ([IntegerType], IntegerType), Application (Variable "f", [Integer 1; Integer 2; Variable "x"]))
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong arity program 2: %b\n" (typecheck program)
|
||||
with WrongArity _ ->
|
||||
Printf.printf "Error wrong arity program 2: error\n"
|
||||
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong return type program *)
|
||||
|
||||
let program =
|
||||
Function
|
||||
(["a"],
|
||||
FunctionType ([IntegerType], BooleanType),
|
||||
(Variable "a")
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong return type program: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong return type program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong specification program *)
|
||||
|
||||
let program =
|
||||
Function
|
||||
(["a"],
|
||||
IntegerType,
|
||||
(Variable "a")
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong specification program: %b\n" (typecheck program)
|
||||
with WrongTypeSpecification _ ->
|
||||
Printf.printf "Error wrong specification program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error wrong input type program *)
|
||||
|
||||
let program =
|
||||
Application (
|
||||
Function
|
||||
(["a"; "b"],
|
||||
FunctionType ([IntegerType; IntegerType], IntegerType),
|
||||
(Variable "a")
|
||||
),
|
||||
[Boolean false]
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error wrong input type program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error wrong input type program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error not a function program *)
|
||||
|
||||
let program =
|
||||
Application (
|
||||
Integer 0,
|
||||
[Boolean false]
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error not a function program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error not a function program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error if branches with different types program *)
|
||||
|
||||
let program =
|
||||
Function (
|
||||
["x"],
|
||||
FunctionType ([IntegerType], IntegerType),
|
||||
IfThenElse (Cmp (Integer 1, Integer 2), Boolean true, Integer 1)
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error if branches with different types program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error if branches with different types program: error\n"
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Error if guard is not a boolean program *)
|
||||
|
||||
let program =
|
||||
Function (
|
||||
["x"],
|
||||
FunctionType ([IntegerType], IntegerType),
|
||||
IfThenElse (Integer 1, Integer 2, Integer 1)
|
||||
)
|
||||
;;
|
||||
|
||||
try
|
||||
Printf.printf "Error if guard is not a boolean program: %b\n" (typecheck program)
|
||||
with WrongType _ ->
|
||||
Printf.printf "Error if guard is not a boolean program: error\n"
|
||||
|
||||
|
||||
|
||||
(* -------------------------------------------------------------------------- *)
|
||||
(* Identity program *)
|
||||
let program =
|
||||
|
||||
Reference in New Issue
Block a user