diff options
Diffstat (limited to 'tests/tools_test.ml')
-rwxr-xr-x | tests/tools_test.ml | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/tests/tools_test.ml b/tests/tools_test.ml index b64afbc..5514404 100755 --- a/tests/tools_test.ml +++ b/tests/tools_test.ml @@ -1,5 +1,43 @@ open OUnit2 +module TestList = struct + + let test_linearize ctx = begin + let input = [ + ['1'; '2'; '3']; + ['A'; 'B']; + ['W'; 'X'; 'Y'; 'Z']; + ['O']; + ] in + + let expected = [ + '1'; 'A'; 'W'; 'O'; 'X'; 'B'; '2'; '3'; 'Y'; 'Z' + ] in + + let result = Tools.List.linearize input in + + let to_string elems = begin + let result_buffer = Buffer.create 16 in + List.iter (Buffer.add_char result_buffer) elems; + Buffer.contents result_buffer + end in + + + assert_equal + ~msg:(Printf.sprintf "Expected %s but got %s" (to_string expected) (to_string result) ) + expected + result + + + end + + let tests = "list_test">::: [ + + "test_list_linearize" >:: test_linearize; + ] + +end + module TestString = struct let _msg ~expected ~result = @@ -67,7 +105,7 @@ module TestDate = struct let test_get_julian_day ctx = begin - let result = Tools.Date.get_julian_day 2016 01 01 + let result = Date.get_julian_day 2016 01 01 and expected = (Num.num_of_int 42370) in (* Check that the num is round *) @@ -88,7 +126,7 @@ module TestDate = struct y2 m2 d2 in - let result = Tools.Date.date_from_julian_day @@ Num.num_of_int 734 + let result = Date.date_from_julian_day @@ Num.num_of_int 734 and expected = (1902, 01, 03) in assert_equal @@ -99,7 +137,7 @@ module TestDate = struct end let test_parse_time ctx = begin - let result = Tools.Date.from_string "1902-01-03T12:34:56" + let result = Date.from_string "1902-01-03T12:34:56" and expected = (Num.num_of_string "3966431/5400") in (* =2415753.52425925925925925925 *) assert_equal @@ -117,7 +155,7 @@ module TestDate = struct h2 m2 s2 in - let result = Tools.Date.time_from_julian_day @@ Tools.Date.from_string "1902-01-03T12:34:56" + 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 @@ -130,9 +168,9 @@ module TestDate = struct let test_time_add_hour ctx = begin - let (result:string) = Tools.Date.from_string "1902-01-03T12:34:56" + let (result:string) = Date.from_string "1902-01-03T12:34:56" |> Num.(add_num ((num_of_int 1) // (num_of_int 2)) ) - |> Tools.Date.to_string in + |> Date.to_string in let expected = "1902-01-04T00:34:56" in @@ -147,9 +185,9 @@ module TestDate = struct let test_time_add_hour2 ctx = begin - let (result:string) = Tools.Date.from_string "1902-01-03T12:34:56" + let (result:string) = Date.from_string "1902-01-03T12:34:56" |> Num.(add_num ((num_of_int 3) // (num_of_int 4)) ) - |> Tools.Date.to_string in + |> Date.to_string in let expected = "1902-01-04T00:34:56" in @@ -204,6 +242,7 @@ end let tests = "tools_test">::: [ TestString.tests; + TestList.tests; "test_get_julian_day" >:: TestDate.test_get_julian_day; "test_from_julian_day" >:: TestDate.test_from_julian_day; |