1
0
Fork 0

Add multiple tests

This commit is contained in:
Mylloon 2024-04-27 12:34:21 +02:00
parent ae73de8f64
commit 3d29e88f2a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -3,6 +3,7 @@ open TypeInference
let tests_typeof =
let x = Identifier.fresh () in
let y = Identifier.fresh () in
let z = Identifier.fresh () in
[ (* IntConst *)
"0", Term.IntConst 0, Some Type.Int
; (* int -> int -> int = <fun> *)
@ -10,7 +11,7 @@ let tests_typeof =
, Term.(Fun (x, Fun (y, Binop (Var x, Plus, Var y))))
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
; (* Not typed variable *)
"x", Term.(Var "x"), Some (Type.Var "x")
"x", Term.(Var "x"), None
; (* Binary operation *)
"1 + 2", Term.(Binop (IntConst 1, Plus, IntConst 2)), Some Type.Int
; (* Pair *)
@ -27,6 +28,20 @@ let tests_typeof =
( "(fun x -> x + 1) (1, 2)"
, Term.(App (Fun (x, Binop (Var x, Plus, IntConst 1)), Pair (IntConst 1, IntConst 2)))
, None )
; (* int -> int -> int = <fun> *)
( "fun x -> fun y -> x * y"
, Term.(Fun (x, Fun (y, Binop (Var x, Times, Var y))))
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
; (* int -> int -> int = <fun> *)
( "fun x -> fun y -> x - y"
, Term.(Fun (x, Fun (y, Binop (Var x, Minus, Var y))))
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
; (* int -> int -> int = <fun> *)
( "fun x -> fun y -> y / x"
, Term.(Fun (x, Fun (y, Binop (Var y, Div, Var x))))
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
; (* Use of a non declared variable *)
"fun x -> fun y -> y / z", Term.(Fun (x, Fun (y, Binop (Var y, Div, Var z)))), None
]
;;