Commit 9cce0b22 authored by Pietro Abate's avatar Pietro Abate
Browse files

Add monomorphic unit tests

All tests are taken from the poly cduce prototype.
All tests pass.
parent 6638cc53
......@@ -6,12 +6,84 @@ open OUnit
let parse_typ s =
let st = Stream.of_string s in
let astpat = Parser.pat st in
let nodepat = Typer.typ Typer.empty_env astpat in
let nodepat = Typer.typ Builtin.env astpat in
Types.descr nodepat
;;
(*
let t1 = Types.descr (Typer.typ Builtin.env (Parser.pat (Stream.of_string "`A :> Int")) );;
let t2 = Types.descr (Typer.typ Builtin.env (Parser.pat (Stream.of_string "Any")) );;
Types.subtype t1 t2 ;;
*)
let subtype_tests = [
"Int" , "Any", true;
"`a | Int" , "`a", false;
"Any" , "Any", true;
"Empty" , "Empty", true;
"Empty" , "Any", true;
"0--*" , "Int", true;
"1--5" , "0--*", true;
"0--*" , "Int", true;
"1--5" , "1--*", true;
"1--5" , "1--5", true;
"Any -> `a" , "Any", true;
"`a -> `b | Int" , "`a -> `b", false;
"`a -> `b" , "`a -> `b", true;
"Any -> `a" , "Any -> Any", true;
"`a -> `b" , "Empty -> Any", true;
"(`a -> `c) | (`b -> `c)" , "(`a & `b) -> `c", true;
"(`a & `b) | (`a & `c)" , "`a & (`b | `c)", true;
"`a & (`b | `c)" , "(`a & `b) | (`a & `c)", true;
"(`a,`b) | (`c,`d)" , "((`a | `c) , (`b | `d))", true;
"(`a , `b & `c)" , "(`a,`b) & (`a,`c)", true;
(*
"mu x . Int -> (Nat , x)" , "mu x . Nat -> (Int , x)", true;
"mu x . (a,x)" , "mu y . (a,y)", true;
*)
"Any" , "Int", false ;
"Any" , "Empty", false ;
"`a -> `b" , "`a", false ;
"Any -> `a" , "Empty", false ;
"Any -> `a" , "Any -> Empty", false ;
"`a -> `b" , "`a -> `c", false ;
"Int" , "0--*", false ;
"1--5" , "1--4", false ;
"Int" , "0--*", false ;
];;
let test_subtype =
"test subtype" >:::
List.map (fun (s1,s2,expected) ->
(Printf.sprintf " %s <: %s " s1 s2) >:: (fun _ ->
let t1 = parse_typ s1 in
let t2 = parse_typ s2 in
let result = Types.subtype t1 t2 in
if result <> expected then
begin
(* Printf.printf "subtyping error %s <: %s\n" s1 s2; *)
Printf.printf "found %b, should be %b\n" result expected
end;
assert_equal result expected
)
) subtype_tests
;;
let all =
"all tests" >::: [
test_subtype;
]
let main () =
OUnit.run_test_tt_main all
;;
main ()
parse_typ "Int";;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment