summary refs log tree commit diff
path: root/lib/game/mill.test.fnl
blob: 604c759d0f9ee6bbdf6ad91c101be0a123e2a653 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(let [{: describe
       : test-end} (require :lib.test)
      {: mill-at?
       : get-candidates
       : move-mills
       : candidate-moves
       : any
       } (require :lib.game.mill)
      {: mills } (require :lib.constants)
      with-mills (partial mill-at? mills)]

  (describe "# MILL" (fn []
    (describe "get-candidates()" (fn [t]
        (t
          (let [move 3
                expected [[1 2 3] [3 15 24]]
                moves [ 1 1 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] ]
            {:given (string.format "a move of %d" move)
            :should "return [[1 2 3] [3 15 24]]" 
            : expected 
            :actual (get-candidates mills move)
            }))
        (t
          (let [move 1
                expected [[1 2 3] [1 10 22]]
                moves [ 0 0 0 ] ]
            {:given (string.format "a move of %d" move)
            :should "return [[1 2 3] [1 10 22]]" 
            : expected 
            :actual (get-candidates mills move) }))
        (t
          (let [move 1
                moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                expected [[1 2 3] [1 10 22]]
               ]
            {:given (string.format "a move of %d" move)
            :should "still return [[1 2 3] [1 10 22]]" 
            : expected 
            :actual (get-candidates mills move) }))))
        
    (describe "any()" (fn [t]
        (t {:given "a table of false false true"
            :should "return true"
            :expected true
            :actual (any [false false true]) })
        (t {:given "a table of true false"
            :should "return true"
            :expected true
            :actual (any [true false]) })
        (t {:given "a single false"
            :should "return false"
            :expected false
            :actual (any [false]) })
        (t {:given "a single true"
            :should "return true"
            :expected true
            :actual (any [true]) })))

    (describe "move-mills()" (fn [t]
      (t
        (let [moves [[1 1 1] [0 2 2]] ]
          {:given "a list of moves"
           :should "turn them into true/false if they are mills"
           :expected [true false]
           :actual (move-mills moves) }))
      (t
        (let [moves [[0 1 1] [0 2 2]] ]
          {:given "no mills"
           :should "should return false"
           :expected [false false]
           :actual (move-mills moves) }))
      (t
        (let [moves [[2 2 2] [2 0 0]] ]
          {:given "mill, no mill"
           :should "should return true false"
           :expected [true false]
           :actual (move-mills moves) }))))

    (describe "candidate-moves()" (fn [t]
      (t (let [spaces [[1 2 3] [1 10 22]]
               moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ]
         {:given "spaces [[1 2 3] [1 10 22]]"
          :should "map to moves"
          :expected [[2 2 2] [2 0 0]]
          :actual (candidate-moves moves spaces)}))))

    (describe "mill-at?()" (fn [t]
        (t 
          (let [move 1
                moves [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ]
            {:given "no mills"
             :should "return false"
             :expected false
             :actual (mill-at? mills moves move)}))
        (t 
          (let [move 4
                moves [1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                with-mills (partial mill-at? mills) 
                with-moves (partial with-mills moves)]
            {:given "a mill but not at Move"
             :should "return false"
             :expected false
             :actual (with-moves move)}))
        (t 
          (let [move 1
                moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                with-mills (partial mill-at? mills) 
                with-moves (partial with-mills moves)]
            {:given "a mill"
             :should "return true"
             :expected true
             :actual (with-moves move) }))
        (t 
          (let [move 1
                moves [2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                with-mills (partial mill-at? mills) 
                with-moves (partial with-mills moves)]
            {:given "a mill"
             :should "return the opposite of false"
             :expected false
             :actual (not (with-moves move)) }))))

    (test-end))))