aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2017-10-22 15:03:18 +0200
committerSébastien Dailly <sebastien@chimrod.com>2017-10-23 22:41:50 +0200
commit3cd6317dc21cfb5bda950ae3ba29daf48e71f006 (patch)
treefbb3a3d9029cc0c32fc539c99a987514d64582da /tests
parentd39d55610e792bd4f6f1c2d452f4f1142b27c489 (diff)
Add functions for date and condition booleans
Diffstat (limited to 'tests')
-rwxr-xr-xtests/sheet_test.ml26
-rwxr-xr-xtests/tools_test.ml55
2 files changed, 72 insertions, 9 deletions
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml
index 1a1bef3..b289b14 100755
--- a/tests/sheet_test.ml
+++ b/tests/sheet_test.ml
@@ -80,6 +80,29 @@ let test_create_indirect_cycle ctx = begin
result
end
+let test_check_BFS ctx = begin
+
+ let s = Sheet.Raw.create
+ (* First set A1 to 3 *)
+ |> Sheet.Raw.add (1,1) @@ Expression.load @@ u"=3"
+ |> snd |> Sheet.Raw.add (1,2) @@ Expression.load @@ u"=A1"
+ |> snd |> Sheet.Raw.add (2,2) @@ Expression.load @@ u"=A1"
+ |> snd |> Sheet.Raw.add (5,5) @@ Expression.load @@ u"=B2"
+ (* A3 = A1 + A1 = 6 *)
+ |> snd |> Sheet.Raw.add (1,3) @@ Expression.load @@ u"=A2 + E5"
+ (* Then set A1 to 2 *)
+ |> snd |> Sheet.Raw.add (1,1) @@ Expression.load @@ u"=2"
+ |> snd in
+ let result = (Sheet.Raw.get_value (1, 3) s) in
+ (* A3 = A1 + A1 = 4 *)
+ let expected = Some (ScTypes.Result (ScTypes.Num (Num.num_of_int 4, None))) in
+
+ assert_equal
+ ~msg:(_msg ~expected ~result)
+ expected
+ result
+end
+
let test_delete ctx = begin
let s = Sheet.Raw.create
@@ -126,7 +149,7 @@ let test_update_succs2 ctx = begin
|> snd |> Sheet.Raw.add (1,2) @@ Expression.load @@ u"=A1/0"
|> snd |> Sheet.Raw.add (1,1) @@ Expression.load @@ u"=2"
|> fst in
- (* Only (1, 1) is updated ; (1, 2) does not change, neither (2, 2) *)
+ (* Only (1, 1) is updated ; (2, 2) does not change, neither (2, 2) *)
let expected = Cell.Set.of_list [(1,1)] in
assert_equal
@@ -139,6 +162,7 @@ let tests = "sheet_test">::: [
"test_ref1" >:: test_create_ref_1;
"test_cycle1" >:: test_create_direct_cycle;
"test_cycle2" >:: test_create_indirect_cycle;
+ "test_BFS" >:: test_check_BFS;
"test_delete" >:: test_delete;
"test_update_succs1" >:: test_update_succs1;
"test_update_succs2" >:: test_update_succs2;
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;