File: test_set.ml

package info (click to toggle)
janest-base 0.17.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,632 kB
  • sloc: ml: 48,653; ansic: 281; javascript: 126; makefile: 14
file content (89 lines) | stat: -rw-r--r-- 2,039 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
open! Import
open! Set

type int_set = Set.M(Int).t [@@deriving compare, equal, hash, sexp]

let%test _ = invariants (of_increasing_iterator_unchecked (module Int) ~len:20 ~f:Fn.id)
let%test _ = invariants (Poly.of_increasing_iterator_unchecked ~len:20 ~f:Fn.id)
let of_list = of_list (module Int)

let%expect_test "split_le_gt" =
  for len = 1 to 4 do
    print_endline "";
    for key = 0 to len + 1 do
      let le, gt = split_le_gt (of_list (List.init len ~f:Int.succ)) key in
      Core.print_s [%sexp (le : int_set), "<=", (key : int), "<", (gt : int_set)]
    done
  done;
  [%expect
    {|
    (() <= 0 < (1))
    ((1) <= 1 < ())
    ((1) <= 2 < ())

    (() <= 0 < (1 2))
    ((1) <= 1 < (2))
    ((1 2) <= 2 < ())
    ((1 2) <= 3 < ())

    (() <= 0 < (1 2 3))
    ((1) <= 1 < (2 3))
    ((1 2) <= 2 < (3))
    ((1 2 3) <= 3 < ())
    ((1 2 3) <= 4 < ())

    (() <= 0 < (1 2 3 4))
    ((1) <= 1 < (2 3 4))
    ((1 2) <= 2 < (3 4))
    ((1 2 3) <= 3 < (4))
    ((1 2 3 4) <= 4 < ())
    ((1 2 3 4) <= 5 < ())
    |}]
;;

let%expect_test "split_lt_ge" =
  for len = 1 to 4 do
    print_endline "";
    for key = 0 to len + 1 do
      let lt, ge = split_lt_ge (of_list (List.init len ~f:Int.succ)) key in
      Core.print_s [%sexp (lt : int_set), "<", (key : int), "<=", (ge : int_set)]
    done
  done;
  [%expect
    {|
    (() < 0 <= (1))
    (() < 1 <= (1))
    ((1) < 2 <= ())

    (() < 0 <= (1 2))
    (() < 1 <= (1 2))
    ((1) < 2 <= (2))
    ((1 2) < 3 <= ())

    (() < 0 <= (1 2 3))
    (() < 1 <= (1 2 3))
    ((1) < 2 <= (2 3))
    ((1 2) < 3 <= (3))
    ((1 2 3) < 4 <= ())

    (() < 0 <= (1 2 3 4))
    (() < 1 <= (1 2 3 4))
    ((1) < 2 <= (2 3 4))
    ((1 2) < 3 <= (3 4))
    ((1 2 3) < 4 <= (4))
    ((1 2 3 4) < 5 <= ())
    |}]
;;

let%test_module "Poly" =
  (module struct
    let%test _ = length Poly.empty = 0
    let%test _ = Poly.equal (Poly.of_list []) Poly.empty

    let%test _ =
      let a = Poly.of_list [ 1; 1 ] in
      let b = Poly.of_list [ "a" ] in
      length a = length b
    ;;
  end)
;;