1
0
Fork 0
This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
unification-pfa/test/test_projet_pfa_23_24.ml

52 lines
1.6 KiB
OCaml
Raw Normal View History

2024-03-11 09:31:56 +01:00
open TypeInference
2024-03-11 15:18:02 +01:00
let tests_typeof =
2024-03-11 09:31:56 +01:00
let x = Identifier.fresh () in
let y = Identifier.fresh () in
2024-03-28 17:17:16 +01:00
[ (* Int Const *)
"0", Term.IntConst 0, Some Type.Int
; (* Correct function *)
( "fun x -> fun y -> x + y"
2024-03-11 15:18:02 +01:00
, Term.(Fun (x, Fun (y, Binop (Var x, Plus, Var y))))
, Some Type.(Arrow (Int, Arrow (Int, Int))) )
2024-03-28 17:17:16 +01:00
; (* 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 )
2024-03-11 15:18:02 +01:00
]
;;
2024-03-11 14:25:40 +01:00
2024-03-11 09:31:56 +01:00
let typeModule = (module Type : Alcotest.TESTABLE with type t = Type.t)
let check_typeof term_text term expected_type =
let open Alcotest in
2024-03-11 15:18:02 +01:00
test_case term_text `Quick (fun () ->
check (option typeModule) "Same type" expected_type (Inference.typeof term))
;;
2024-03-11 09:31:56 +01:00
let () =
let open Alcotest in
2024-03-11 15:18:02 +01:00
run
"Inference"
[ ( "typeof"
, List.map
(fun (term_text, term, expected_type) ->
check_typeof term_text term expected_type)
tests_typeof )
2024-03-11 09:31:56 +01:00
]
2024-03-11 15:18:02 +01:00
;;