aboutsummaryrefslogtreecommitdiff
path: root/tests/dataType_test.ml
blob: 3bf51adf4b2dcb93bafe03f97a1c94d4e355b797 (plain)
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
open OUnit2
module N = DataType.Num

let test_num_add n1 n2 result ctx = begin
  assert_equal
    ~cmp:(Num.(=/))
    result
    (N.to_num @@ N.add n1 n2)
end

let test_num_mult n1 n2 result ctx = begin
  assert_equal
    ~cmp:(Num.(=/))
    result
    (N.to_num @@ N.mult n1 n2)
end

let test_num_sub n1 n2 result ctx = begin
  assert_equal
    ~cmp:(Num.(=/))
    result
    (N.to_num @@ N.sub n1 n2)
end

let n1 = N.of_num (Num.num_of_int 1)
let n2 = N.of_num (Num.num_of_int 2)

let num_tests = "num_test">::: [

    "test_add"       >:: test_num_add n1     n1    (Num.num_of_int 2);
    "test_add_nan1"  >:: test_num_add n1     N.nan (Num.num_of_int 1);
    "test_add_nan2"  >:: test_num_add N.nan  n1    (Num.num_of_int 1);
    "test_add_nan3"  >:: test_num_add N.nan  N.nan (Num.num_of_int 0);

    "test_mult"      >:: test_num_mult n2    n1    (Num.num_of_int 2);
    "test_mult_nan1" >:: test_num_mult n1    N.nan (Num.num_of_int 0);
    "test_mult_nan2" >:: test_num_mult N.nan n1    (Num.num_of_int 0);
    "test_mult_nan3" >:: test_num_mult N.nan N.nan (Num.num_of_int 0);

    "test_sub"       >:: test_num_sub n1     n1    (Num.num_of_int 0);
    "test_sub_nan1"  >:: test_num_sub n1     N.nan (Num.num_of_int 1);
    "test_sub_nan2"  >:: test_num_sub N.nan  n1    (Num.num_of_int (-1));
    "test_sub_nan3"  >:: test_num_sub N.nan  N.nan (Num.num_of_int 0);
 ]