diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/dataType_test.ml | 33 | ||||
-rwxr-xr-x | tests/expressionParser_test.ml | 6 | ||||
-rwxr-xr-x | tests/expression_test.ml | 18 | ||||
-rwxr-xr-x | tests/odf/odf_ExpressionParser_test.ml | 2 | ||||
-rwxr-xr-x | tests/sheet_test.ml | 4 | ||||
-rwxr-xr-x | tests/tools_test.ml | 117 |
6 files changed, 75 insertions, 105 deletions
diff --git a/tests/dataType_test.ml b/tests/dataType_test.ml index 3bf51ad..ddb45ae 100755 --- a/tests/dataType_test.ml +++ b/tests/dataType_test.ml @@ -3,42 +3,31 @@ module N = DataType.Num let test_num_add n1 n2 result ctx = begin
assert_equal
- ~cmp:(Num.(=/))
+ ~cmp:(=)
result
- (N.to_num @@ N.add n1 n2)
+ (N.to_int @@ N.add n1 n2)
end
let test_num_mult n1 n2 result ctx = begin
assert_equal
- ~cmp:(Num.(=/))
+ ~cmp:(=)
result
- (N.to_num @@ N.mult n1 n2)
+ (N.to_int @@ N.mult n1 n2)
end
let test_num_sub n1 n2 result ctx = begin
assert_equal
- ~cmp:(Num.(=/))
+ ~cmp:(=)
result
- (N.to_num @@ N.sub n1 n2)
+ (N.to_int @@ 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 n1 = N.of_int 1
+let n2 = N.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);
+ "test_add" >:: test_num_add n1 n1 2;
+ "test_mult" >:: test_num_mult n2 n1 2;
+ "test_sub" >:: test_num_sub n1 n1 0;
]
diff --git a/tests/expressionParser_test.ml b/tests/expressionParser_test.ml index 30bd665..12ceeb0 100755 --- a/tests/expressionParser_test.ml +++ b/tests/expressionParser_test.ml @@ -20,7 +20,7 @@ let test_num ctx = begin let expected = Expression.Formula ( Expression.Expression ( ScTypes.Value (ScTypes.number ( - DataType.Num.of_num (Num.num_of_int 1) + DataType.Num.of_int 1 ) ))) in let result = load_expr "=1" in @@ -54,7 +54,7 @@ let test_call2 ctx = begin Expression.Expression ( ScTypes.Call ( u"foo2", [ScTypes.Value (ScTypes.number ( - DataType.Num.of_num (Num.num_of_int 4) + DataType.Num.of_int 4 ))]))) in let result = load_expr "=foo2(4)" in @@ -82,5 +82,5 @@ let tests = "expression_parser_test">::: [ "test_num" >:: test_num; "test_call" >:: test_call; "test_call2" >:: test_call2; - "test_ref" >:: test_ref; + "test_ref" >:: test_ref; ] diff --git a/tests/expression_test.ml b/tests/expression_test.ml index 2fa4d9b..5def730 100755 --- a/tests/expression_test.ml +++ b/tests/expression_test.ml @@ -6,11 +6,11 @@ let u = UTF8.from_utf8string let _msg ~expected ~result = let get_type = function - | Expression.Basic ScTypes.Num (ScTypes.Number, _) -> "N" - | Expression.Basic ScTypes.Num (ScTypes.Date, _) -> "D" - | Expression.Basic ScTypes.Str _ -> "S" - | Expression.Basic ScTypes.Bool _ -> "B" - | Expression.Formula _ -> "F" in + | Expression.Basic ScTypes.Num (ScTypes.Number, _) -> "N" + | Expression.Basic ScTypes.Num (ScTypes.Date, _) -> "D" + | Expression.Basic ScTypes.Str _ -> "S" + | Expression.Basic ScTypes.Bool _ -> "B" + | Expression.Formula _ -> "F" in Printf.sprintf "Expected %s:%s but got %s:%s" (UTF8.raw_encode @@ Expression.show expected) @@ -53,7 +53,7 @@ let test_num ctx = begin let result = Expression.load @@ u"123" in let expected = Expression.load_expr @@ Expression.Basic ( ScTypes.number ( - DataType.Num.of_num @@ Num.num_of_int 123 + DataType.Num.of_int 123 )) in assert_equal expected result end @@ -62,7 +62,7 @@ let test_float ctx = begin let result = Expression.load @@ u"12.45" in let expected = Expression.load_expr @@ Expression.Basic ( ScTypes.number ( - DataType.Num.of_num @@ T.Num.of_float_string "12.45" + DataType.Num.of_float @@ float_of_string "12.45" )) in assert_equal expected result end @@ -71,7 +71,7 @@ let test_relative ctx = begin let result = Expression.load @@ u"-123" in let expected = Expression.load_expr @@ Expression.Basic ( ScTypes.number ( - DataType.Num.of_num @@ Num.num_of_int (-123) + DataType.Num.of_int (-123) )) in assert_equal expected result end @@ -80,7 +80,7 @@ let test_date ctx = begin let result = Expression.load @@ u"1900/01/01" and expected = Expression.load_expr @@ Expression.Basic ( ScTypes.date ( - DataType.Num.of_num @@ Date.get_julian_day 1900 01 01 + DataType.Date.get_julian_day 1900 01 01 )) in assert_equal expected result end diff --git a/tests/odf/odf_ExpressionParser_test.ml b/tests/odf/odf_ExpressionParser_test.ml index 8b4e4ff..18efe96 100755 --- a/tests/odf/odf_ExpressionParser_test.ml +++ b/tests/odf/odf_ExpressionParser_test.ml @@ -15,7 +15,7 @@ let _msg ~(expected:ScTypes.expression) ~(result:ScTypes.expression) = let build_num value = ScTypes.number (
- DataType.Num.of_num @@ Num.num_of_int value
+ DataType.Num.of_int value
)
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml index 7353dc6..9218134 100755 --- a/tests/sheet_test.ml +++ b/tests/sheet_test.ml @@ -16,9 +16,7 @@ let _msg ~expected ~result = begin (get_string result) end -let build_num value = ScTypes.number ( - DataType.Num.of_num @@ Num.num_of_int value -) +let build_num value = ScTypes.number @@ DataType.Num.of_int value (** Test a simple references between two cells *) let test_create_ref_1 ctx = begin diff --git a/tests/tools_test.ml b/tests/tools_test.ml index 5514404..74a3acd 100755 --- a/tests/tools_test.ml +++ b/tests/tools_test.ml @@ -98,21 +98,41 @@ end module TestDate = struct - let _msg ~expected ~result = - Printf.sprintf "Expected %s but got %s" - (Num.string_of_num expected) - (Num.string_of_num result) + module Float = struct + + type t = float + let add = ( +. ) + let sub = ( -. ) + let mult = ( *. ) + let div = ( /. ) + + let floor = Pervasives.floor + + let of_int = float_of_int + + let to_int = int_of_float + let to_float x = x + + end + + module FDate = Date.Make(Float) + + let epsilon = 1.0e-5 + + let (=.) a b = (abs_float (a-.b)) < epsilon let test_get_julian_day ctx = begin - let result = Date.get_julian_day 2016 01 01 - and expected = (Num.num_of_int 42370) in + let result = FDate.get_julian_day 2016 01 01 + and expected = 42370. in - (* Check that the num is round *) - assert_equal true (Num.is_integer_num result); + let _msg ~expected ~result = + Printf.sprintf "Expected %f but got %f" + expected + result in assert_equal - ~cmp:Num.(=/) + ~cmp:(=.) ~msg:(_msg ~expected ~result) expected result @@ -126,7 +146,7 @@ module TestDate = struct y2 m2 d2 in - let result = Date.date_from_julian_day @@ Num.num_of_int 734 + let result = FDate.date_from_julian_day 734. and expected = (1902, 01, 03) in assert_equal @@ -137,11 +157,18 @@ module TestDate = struct end let test_parse_time ctx = begin - let result = Date.from_string "1902-01-03T12:34:56" - and expected = (Num.num_of_string "3966431/5400") in + let result = FDate.from_string "1902-01-03T12:34:56" + + and expected = 3966431. /. 5400. (* =2415753.52425925925925925925 *) + + and _msg ~expected ~result = + Printf.sprintf "Expected %f but got %f" + expected + result in + assert_equal - ~cmp:Num.(=/) + ~cmp:(=.) ~msg:(_msg ~expected ~result) expected result @@ -150,17 +177,17 @@ module TestDate = struct let test_time_from_julian_day ctx = begin let _msg (h1, m1, s1) (h2, m2, s2) = - Printf.sprintf "Expected %f:%f:%f but got %f:%f:%f" + Printf.sprintf "Expected %d:%d:%f but got %d:%d:%f" h1 m1 s1 h2 m2 s2 in - let result = Date.time_from_julian_day @@ Date.from_string "1902-01-03T12:34:56" - |> Tools.Tuple3.map (Num.float_of_num) - and expected = (12., 34., 56.) in + let result = FDate.time_from_julian_day @@ FDate.from_string "1902-01-03T12:34:56" + and expected = (12, 34, 56.) in assert_equal ~msg:(_msg expected result) + ~cmp:(fun (a, b, c) (a', b', c') -> a = a' && b = b' && c =. c') expected result end @@ -168,9 +195,9 @@ module TestDate = struct let test_time_add_hour ctx = begin - let (result:string) = Date.from_string "1902-01-03T12:34:56" - |> Num.(add_num ((num_of_int 1) // (num_of_int 2)) ) - |> Date.to_string in + let (result:string) = FDate.from_string "1902-01-03T12:34:56" + |> fun x -> (x +. (1. /. 2.)) + |> FDate.to_string in let expected = "1902-01-04T00:34:56" in @@ -185,9 +212,9 @@ module TestDate = struct let test_time_add_hour2 ctx = begin - let (result:string) = Date.from_string "1902-01-03T12:34:56" - |> Num.(add_num ((num_of_int 3) // (num_of_int 4)) ) - |> Date.to_string in + let (result:string) = FDate.from_string "1902-01-03T12:34:56" + |> fun x -> (x +. (3. /. 4.)) + |> FDate.to_string in let expected = "1902-01-04T00:34:56" in @@ -201,44 +228,6 @@ module TestDate = struct end -(* -module TestLocale = struct - - let test_empty_string_length ctx = begin - - Tools.Locale.set Tools.Locale.LC_CTYPE "en_US.UTF-8"; - let result = Tools.Locale.length "" in - let expected = 0 in - Tools.Locale.set Tools.Locale.LC_CTYPE "C"; - - assert_equal expected result - end - - let test_one_byte_length ctx = begin - - Tools.Locale.set Tools.Locale.LC_CTYPE "en_US.UTF-8"; - let result = Tools.Locale.length "A" in - let expected = 1 in - Tools.Locale.set Tools.Locale.LC_CTYPE "C"; - - assert_equal expected result - end - - (** Encode an two-bytes UTF-8 string and check that the length is only one - character*) - let test_two_byte_length ctx = begin - - Tools.Locale.set Tools.Locale.LC_CTYPE "en_US.UTF-8"; - let result = Tools.Locale.length "\xc3\x80" in - let expected = 1 in - Tools.Locale.set Tools.Locale.LC_CTYPE "C"; - - assert_equal expected result - end - -end -*) - let tests = "tools_test">::: [ TestString.tests; @@ -250,10 +239,4 @@ let tests = "tools_test">::: [ "test_time_from_julian_day" >:: TestDate.test_time_from_julian_day; "test_time_add_hour" >:: TestDate.test_time_add_hour; -(* - (** Locale test *) - "test_locale_length0" >:: TestLocale.test_empty_string_length; - "test_locale_length1" >:: TestLocale.test_one_byte_length; - "test_locale_length2" >:: TestLocale.test_two_byte_length; -*) ] |