tallyingTest.ml 1.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
open OUnit

(* open Types *)

let parse_typ s =
  let st = Stream.of_string s in
  let astpat = Parser.pat st in 
  let nodepat = Typer.typ Builtin.env astpat in
  Types.descr nodepat
;;

12
13
14
15
let cup = Types.Tallying.CS.S.cup
let cap = Types.Tallying.CS.cap
let singleton = Types.Tallying.CS.singleton

16
let norm_tests = [
17
18
19
20
21
22
23
24
25
26
27
28
  "Int \\ (`$A | `$B)", singleton (false,`Var "A",parse_typ "Int \\ `$B");
  "(`$A -> Int) \\ (`$B -> `$B)", 
                    cup 
                      (singleton (true,`Var "B",parse_typ "Empty")) 
                      (cap 
                        (singleton (false , `Var "B",parse_typ "`$A"))
                        (singleton (false , `Var "B",parse_typ "Int"))
                      );
  "`$B", singleton (true,`Var "B",parse_typ "Empty");
  "`$B \\ `$A", singleton (false , `Var "B",parse_typ "`$A");
  "Int \\ `$B", singleton (false , `Var "B",parse_typ "Int");
  "(Int & Bool -> Int) \\ (`$A -> `$B)"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
]

let test_norm =
  "test tallying norm" >:::
    List.map (fun (t,expected) ->
      (Printf.sprintf " %s " t) >:: (fun _ ->
        let ll = Types.Tallying.norm (parse_typ t) in
        assert_equal ll expected
      )
    ) norm_tests
;;

let all =
  "all tests" >::: [
    test_norm;
  ]
 
let main () =
  OUnit.run_test_tt_main all
;;
 
main ()