From e1d1d3ef0c1e2605b03d0a6b74ff263017ce2613 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 28 Mar 2024 17:17:16 +0100 Subject: [PATCH] Add testing --- test/test_projet_pfa_23_24.ml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/test_projet_pfa_23_24.ml b/test/test_projet_pfa_23_24.ml index 0f9cd57..591711c 100644 --- a/test/test_projet_pfa_23_24.ml +++ b/test/test_projet_pfa_23_24.ml @@ -1,13 +1,32 @@ open TypeInference let tests_typeof = - (* TODO: add more tests *) let x = Identifier.fresh () in let y = Identifier.fresh () in - [ "0", Term.IntConst 0, Some Type.Int - ; ( "fun x -> fun y -> x+y" + [ (* Int Const *) + "0", Term.IntConst 0, Some Type.Int + ; (* Correct function *) + ( "fun x -> fun y -> x + y" , Term.(Fun (x, Fun (y, Binop (Var x, Plus, Var y)))) , Some Type.(Arrow (Int, Arrow (Int, Int))) ) + ; (* Not typed variable *) + "x", Var "x", None + ; (* Operation *) + "1 + 2", Binop (IntConst 1, Plus, IntConst 2), Some Int + ; (* Pair *) + "(1, 2)", Pair (IntConst 1, IntConst 2), Some (Product (Int, Int)) + ; (* Projection with first *) + "fst (1, 2)", Proj (First, Pair (IntConst 1, IntConst 2)), Some Int + ; (* Projection with second *) + "snd (1, 2)", Proj (Second, Pair (IntConst 1, IntConst 2)), Some Int + ; (* Apply (int) into (fun : int -> int) *) + ( "(fun x -> x + 1) 5" + , App (Fun (x, Binop (Var x, Plus, IntConst 1)), IntConst 5) + , Some Type.Int ) + ; (* Apply product (int * int) into a not compatible function (fun : int -> int) *) + ( "(fun x -> x + 1) (1, 2)" + , App (Fun (x, Binop (Var x, Plus, IntConst 1)), Pair (IntConst 1, IntConst 2)) + , None ) ] ;;