aboutsummaryrefslogtreecommitdiff
path: root/tests/selection_test.ml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/selection_test.ml')
-rw-r--r--tests/selection_test.ml78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/selection_test.ml b/tests/selection_test.ml
new file mode 100644
index 0000000..940abd7
--- /dev/null
+++ b/tests/selection_test.ml
@@ -0,0 +1,78 @@
+(*
+This file is part of licht.
+
+licht is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+licht is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with licht. If not, see <http://www.gnu.org/licenses/>.
+*)
+
+open OUnit2
+module S = Selection
+
+(* Test if a single cell is selected with an axe *)
+let test_selected_single axe1 axe2 env = begin
+
+ let selection = Selection.create (10, 10) in
+
+ assert_equal
+ true
+ (Selection.is_selected axe1 selection);
+
+ assert_equal
+ false
+ (Selection.is_selected axe2 selection);
+end
+
+let test_selected_multiple axe1 axe2 env = begin
+
+ let selection = Selection.extends
+ (Actions.Left 1)
+ (Selection.create (10, 10)) in
+
+ assert_equal
+ true
+ (Selection.is_selected axe1 selection);
+
+ assert_equal
+ false
+ (Selection.is_selected axe2 selection);
+end
+
+let test_extract_single env = begin
+
+ let selection = Selection.create (10, 10) in
+
+ assert_equal
+ (10, 10)
+ (Selection.extract selection);
+end
+let test_extract_multiple env = begin
+
+ let selection = Selection.extends
+ (Actions.Left 1)
+ (Selection.create (10, 10)) in
+
+ assert_equal
+ (9, 10)
+ (Selection.extract selection);
+end
+
+let tests = "selection_test">::: [
+ "test_selected1" >:: test_selected_single (S.Horizontal 10) (S.Horizontal 11);
+ "test_selected2" >:: test_selected_single (S.Vertical 10) (S.Vertical 11);
+ "test_selected3" >:: test_selected_single (S.Cell (10, 10)) (S.Cell (11, 11));
+ "test_selected4" >:: test_selected_multiple (S.Horizontal 10) (S.Horizontal 11);
+ "test_selected5" >:: test_selected_multiple (S.Vertical 10) (S.Vertical 11);
+ "test_selected6" >:: test_selected_multiple (S.Cell (10, 10)) (S.Cell (11, 11));
+ "test_extract1 " >:: test_extract_single;
+ "test_extract2 " >:: test_extract_multiple;
+]