summary refs log tree commit diff
path: root/lib/mill.test.fnl
blob: 04f7e977acfe4ea0c1f10b2e97396997ad3326e6 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(let [{: describe
       :end test-end} (require :lib.test)
      {: mill-at?
       : get-candidates
       : move-mills
       : candidate-moves
       : any
       } (require :lib.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 spaces moves) 
          }
         )
       )  
    ))

    (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))))