aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2017-11-29 15:51:39 +0100
committerSébastien Dailly <sebastien@chimrod.com>2018-02-09 10:27:07 +0100
commitbb48738c4111f5f4e2faa40fe67ae1b8b9d7c2eb (patch)
treefdea7f0473453423f052700c7cf807640589ab2f /tests
parent754713ed399110d5a199653a684d65cbe258bf5d (diff)
Rework on the Sheet.ml API : removed low level functions, made the sheet mutable
Diffstat (limited to 'tests')
-rwxr-xr-xtests/sheet_test.ml150
1 files changed, 70 insertions, 80 deletions
diff --git a/tests/sheet_test.ml b/tests/sheet_test.ml
index dfa8da4..197cf88 100755
--- a/tests/sheet_test.ml
+++ b/tests/sheet_test.ml
@@ -23,11 +23,11 @@ let build_num value = ScTypes.Type.number @@ DataType.Num.of_int value
(** Test a simple references between two cells *)
let test_create_ref_1 ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (3,3) (Expression.load @@ u"=-1") catalog
- |> snd |> Sheet.Raw.add (0,0) (Expression.load @@ u"=C3") catalog
- |> snd in
- let result = (Sheet.Raw.get_value (0, 0) s) in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=-1") (3,3) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=C3") (0,0) s;
+
+ let _, result, _ = Sheet.get_cell (0, 0) s in
let expected = Some (ScTypes.Result.Ok (build_num (-1))) in
assert_equal
@@ -38,14 +38,12 @@ end
let test_create_ref_2 ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (2,2) (Expression.load @@ u"=C3") catalog
- |> snd |> Sheet.Raw.add (3,3) (Expression.load @@ u"=A1") catalog
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"123") catalog
- |> snd in
-
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=C3") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (3,3) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"123") (1,1) s;
- let result = (Sheet.Raw.get_value (2, 2) s) in
+ let _, result, _ = Sheet.get_cell (2, 2) s in
let expected = Some (ScTypes.Result.Ok (build_num 123)) in
assert_equal
@@ -56,10 +54,10 @@ end
let test_create_direct_cycle ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (2,2) (Expression.load @@ u"=B2 + 1") catalog
- |> snd in
- let result = (Sheet.Raw.get_value (2, 2) s) in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=B2 + 1") (2,2) s;
+
+ let _, result, _ = Sheet.get_cell (2, 2) s in
let expected = Some (ScTypes.Result.Error Errors.TypeError) in
assert_equal
@@ -71,11 +69,11 @@ end
(** Overide the value after a cycle. *)
let test_recover_from_cycle ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (2,2) (Expression.load @@ u"=B2 + 1") catalog
- |> snd |> Sheet.Raw.add (2,2) (Expression.load @@ u"=6") catalog
- |> snd in
- let result = (Sheet.Raw.get_value (2, 2) s) in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=B2 + 1") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=6") (2,2) s;
+
+ let _, result, _ = Sheet.get_cell (2, 2) s in
let expected = Some (ScTypes.Result.Ok (build_num (6))) in
assert_equal
@@ -86,13 +84,13 @@ end
let test_create_indirect_cycle ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (2,2) (Expression.load @@ u"=A1") catalog
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"=2") catalog
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"=B2+1") catalog
- |> snd |> Sheet.Raw.add (0,0) (Expression.load @@ u"=A1") catalog
- |> snd in
- let result = (Sheet.Raw.get_value (0, 0) s) in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=2") (1,1) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=B2+1") (1,1) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (0,0) s;
+
+ let _, result, _ = Sheet.get_cell (0, 0) s in
let expected = Some (ScTypes.Result.Error Errors.Cycle) in
assert_equal
@@ -103,18 +101,18 @@ end
let test_check_cycle3 ctx = begin
- let s = Sheet.Raw.empty
- (* First set A1 to 3 *)
- |> Sheet.Raw.add (1,1) (Expression.load @@ u"=3") catalog
- |> snd |> Sheet.Raw.add (1,2) (Expression.load @@ u"=A1") catalog
- |> snd |> Sheet.Raw.add (2,2) (Expression.load @@ u"=A1") catalog
- |> snd |> Sheet.Raw.add (5,5) (Expression.load @@ u"=B2") catalog
- (* A3 = A1 + A1 = 6 *)
- |> snd |> Sheet.Raw.add (1,3) (Expression.load @@ u"=A2 + E5") catalog
- (* Then set A1 to 2 *)
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"=2") catalog
- |> snd in
- let result = (Sheet.Raw.get_value (1, 3) s) in
+ let s = Sheet.create catalog in
+ (* First set A1 to 3 *)
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=3") (1,1) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (1,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=B2") (5,5) s;
+ (* A3 = A1 + A1 = 6 *)
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A2 + E5") (1,3) s;
+ (* Then set A1 to 2 *)
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=2") (1,1) s;
+
+ let _, result, _ = Sheet.get_cell (1, 3) s in
(* A3 = A1 + A1 = 4 *)
let expected = Some (ScTypes.Result.Ok (build_num 4)) in
@@ -126,13 +124,12 @@ end
let test_delete ctx = begin
- let s = Sheet.Raw.empty
- |> Sheet.Raw.add (2,2) (Expression.load @@ u"=C3") catalog
- |> snd |> Sheet.Raw.add (3,3) (Expression.load @@ u"=A1") catalog
- |> snd |> Sheet.Raw.remove (2,2) catalog
- |> snd |> Sheet.Raw.remove (3,3) catalog
- |> snd in
- let result = (Sheet.Raw.get_value (3, 3) s) in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=C3") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1") (3,3) s;
+ ignore @@ Sheet.delete (Selection.create (2,2)) s;
+ ignore @@ Sheet.delete (Selection.create (3,3)) s;
+ let _, result, _ = Sheet.get_cell (3, 3) s in
let expected = None in
assert_equal
@@ -143,12 +140,12 @@ end
let test_update_succs1 ctx = begin
- let result = Sheet.Raw.empty
- |> Sheet.Raw.add (1,1) (Expression.load @@ u" =1") catalog
- |> snd |> Sheet.Raw.add (2,2) (Expression.load @@ u"=A2") catalog
- |> snd |> Sheet.Raw.add (1,2) (Expression.load @@ u"=A1/1") catalog
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"=2") catalog
- |> fst in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u" =1") (1,1) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A2") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1/1") (1,2) s;
+
+ let result = Sheet.add ~history:false (Expression.load @@ u"=2") (1,1) s in
(* All the cells are updated by the change *)
let expected = Cell.Set.of_list [(1,1); (1, 2); (2,2)] in
@@ -164,12 +161,13 @@ end
let test_update_succs2 ctx = begin
- let result = Sheet.Raw.empty
- |> Sheet.Raw.add (1,1) (Expression.load @@ u"=1") catalog
- |> snd |> Sheet.Raw.add (2,2) (Expression.load @@ u"=A2") catalog
- |> snd |> Sheet.Raw.add (1,2) (Expression.load @@ u"=A1/0") catalog
- |> snd |> Sheet.Raw.add (1,1) (Expression.load @@ u"=2") catalog
- |> fst in
+ let s = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=1") (1,1) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A2") (2,2) s;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=A1/0") (1,2) s;
+
+ let result = Sheet.add ~history:false (Expression.load @@ u"=2") (1,1) s in
+
(* Only (1, 1) is updated ; (2, 2) does not change, neither (2, 2) *)
let expected = Cell.Set.of_list [(1,1)] in
@@ -180,19 +178,14 @@ end
let test_paste_undo ctx = begin
- let empty = Sheet.create catalog Sheet.Raw.empty in
-
(* The expected result for the whole test *)
let expected = Some (ScTypes.Result.Ok (ScTypes.Type.number (DataType.Num.of_int 6))) in
- let sheet = empty
- |> Tools.Option.test @@ Sheet.move (Actions.Absolute (2, 1))
- |> Sheet.add (Expression.load @@ u"=6")
- |> snd
- |> Tools.Option.test @@ Sheet.move (Actions.Absolute (1, 1))
- |> Sheet.add (Expression.load @@ u"=B1")
- |> snd in
- let result = Sheet.Raw.get_value (1, 1) sheet.Sheet.data in
+ let sheet = Sheet.create catalog in
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=6") (2, 1) sheet;
+ ignore @@ Sheet.add ~history:false (Expression.load @@ u"=B1") (1, 1) sheet;
+
+ let _, result, _ = Sheet.get_cell (1, 1) sheet in
(* Ensure the value is correctly evaluated *)
assert_equal
@@ -200,17 +193,14 @@ let test_paste_undo ctx = begin
expected
result;
- let sheet2 =
- (* Copy the cell *)
- fst @@ Sheet.yank sheet
- |> Tools.Option.test @@ Sheet.move (Actions.Absolute (2, 1))
- (* Paste it on another value *)
- |> Sheet.paste
- |> fst
- (* Undo the paste *)
- |> Tools.Option.test @@ Sheet.undo in
-
- let result = Sheet.Raw.get_value (1, 1) sheet2.Sheet.data in
+ (* Copy the cell *)
+ ignore @@ Sheet.yank (Selection.create (1, 1)) sheet;
+ (* Paste it on another value *)
+ ignore @@ Sheet.paste (2, 1) sheet;
+ (* Undo the paste *)
+ assert_equal true (Sheet.undo sheet);
+
+ let _, result, _ = Sheet.get_cell (1, 1) sheet in
(* The value should be the same as the first evaluation *)
assert_equal