diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2016-11-21 17:06:19 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2017-01-01 13:30:43 +0100 |
commit | 023c11470e32744a43b7e3c7c248f3c47ebdc687 (patch) | |
tree | 832e04c2923295d5adf61e58d9a333afb5b26c77 /tests | |
parent | ef312564ca84a2b49fc291434d8fb2f8501bb618 (diff) |
Use gadt for function catalog
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/dataType_test.ml | 44 | ||||
-rwxr-xr-x | tests/expression_test.ml | 1 | ||||
-rwxr-xr-x | tests/sheet_test.ml | 8 | ||||
-rwxr-xr-x | tests/test.ml | 1 |
4 files changed, 49 insertions, 5 deletions
diff --git a/tests/dataType_test.ml b/tests/dataType_test.ml new file mode 100755 index 0000000..3bf51ad --- /dev/null +++ b/tests/dataType_test.ml @@ -0,0 +1,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);
+ ]
diff --git a/tests/expression_test.ml b/tests/expression_test.ml index 3674b9a..d1ac2ba 100755 --- a/tests/expression_test.ml +++ b/tests/expression_test.ml @@ -11,7 +11,6 @@ let _msg ~expected ~result = | Expression.Basic ScTypes.Date _ -> "D" | Expression.Basic ScTypes.Undefined -> "U" | Expression.Basic ScTypes.Bool _ -> "B" - | Expression.Basic ScTypes.List _ -> "L" | Expression.Formula _ -> "F" in Printf.sprintf "Expected %s:%s but got %s:%s" diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml index f63d76f..de42730 100755 --- a/tests/sheet_test.ml +++ b/tests/sheet_test.ml @@ -15,7 +15,7 @@ let test_create_ref_1 ctx = begin |> snd |> Sheet.Raw.add (0,0) @@ Expression.load @@ u"=C3" |> snd in let result = (Sheet.Raw.get_value (0, 0) s) in - let expected = (ScTypes.Result (ScTypes.Num (Num.num_of_int (-1), Some (u"-1")))) in + let expected = (ScTypes.Result (ScTypes.Num (Num.num_of_int (-1), None))) in assert_equal ~msg:(_msg ~expected ~result) @@ -33,7 +33,7 @@ let test_create_ref_2 ctx = begin let result = (Sheet.Raw.get_value (2, 2) s) in - let expected = ScTypes.Result (ScTypes.Num (Num.num_of_int 123, Some (u"123"))) in + let expected = ScTypes.Result (ScTypes.Num (Num.num_of_int 123, None)) in assert_equal ~msg:(_msg ~expected ~result) @@ -47,7 +47,7 @@ let test_create_direct_cycle ctx = begin |> Sheet.Raw.add (2,2) @@ Expression.load @@ u"=B2" |> snd in let result = (Sheet.Raw.get_value (2, 2) s) in - let expected = ScTypes.Error Sheet.Raw.Cycle in + let expected = ScTypes.Error Errors.TypeError in assert_equal ~msg:(_msg ~expected ~result) @@ -63,7 +63,7 @@ let test_create_indirect_cycle ctx = begin |> snd |> Sheet.Raw.add (0,0) @@ Expression.load @@ u"=A1" |> snd in let result = (Sheet.Raw.get_value (0, 0) s) in - let expected = ScTypes.Result ScTypes.Undefined in + let expected = ScTypes.Error Errors.TypeError in assert_equal ~msg:(_msg ~expected ~result) diff --git a/tests/test.ml b/tests/test.ml index 1bfd6c1..8a24cd5 100755 --- a/tests/test.ml +++ b/tests/test.ml @@ -1,6 +1,7 @@ let () = let tests = OUnit2.test_list [ Tools_test.tests; + DataType_test.num_tests; ExpressionParser_test.tests; Expression_test.tests; Sheet_test.tests; |