open Alcotest
open Syntax
open Parse_tree
open Dynamizer

let ann term = annotate term ()

let make_test_count_ty name ty expected =
  let test () =
    let result = Count.count_ty (annotate ty ()) in
    check (pair int int) "same lattice size and number of static types" expected
      result
  in
  test_case name `Quick test

let count_ty_tests =
  let open Type in
  [
    make_test_count_ty "any" Any (1, 1);
    make_test_count_ty "int" Int (2, 1);
    make_test_count_ty "bool" Bool (2, 1);
    make_test_count_ty "var" (Var "a") (2, 1);
    make_test_count_ty "arrow" (Arrow ([ ann Int ], ann Bool)) (5, 3);
    make_test_count_ty "product" (Product [ ann Int; ann Bool ]) (5, 3);
    make_test_count_ty "nested_arrow"
      (Arrow ([ ann Int ], ann (Arrow ([ ann Any ], ann Int))))
      (7, 5);
    make_test_count_ty "nested_product"
      (Product
         [ ann Int; ann Bool; ann (Product [ ann Any; ann Int; ann Bool ]) ])
      (21, 7);
    make_test_count_ty "n-ary_arrow"
      (Arrow ([ ann Int; ann Bool ], ann (Arrow ([ ann Any ], ann Int))))
      (13, 6);
    make_test_count_ty "vec" (Vec (ann Int)) (3, 2);
  ]

let () = run "Dynamizer Tests" [ ("count_ty", count_ty_tests) ]
