aboutsummaryrefslogtreecommitdiff
path: root/tests/selection_test.ml
blob: 940abd7b390d879a7da318f5b7d6055c1aab601a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
]