summary refs log tree commit diff
path: root/lib/mill.test.fnl
blob: 8bd3522358e298657d0a12eae22e8e134ccc0797 (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
(let [{: describe
       :end test-end} (require :lib.test)
      {: mill?
       : get-candidates
       : candidates->moves
       : moves->mills
       : any
       } (require :lib.mill)
      {: mills } (require :lib.constants)
      with-mills (partial mill? 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)
           }))))
				

    (describe "#candidates->moves()" (fn [t]
          (t 
						(let [candidates [[1 2 3] [1 10 22]] 
								  moves [0 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 2]
								  expected [[:x 1 1] [:x 2 2]]
								  move 1
								  player 2
								  ]
							 {:given "a list of spaces and of current moves"
								:should "return a map of spaces to moves"
								: expected
								:actual (candidates->moves candidates moves move player)
								}))
          (t 
						(let [candidates [[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 ]
							 		expected [[1 1 :x] [:x 0 0]]
									move 3
									player 1
									]
							 {:given "a list of candidates and of current moves"
								:should "return an x-map of spaces to moves"
								: expected
								:actual (candidates->moves candidates moves move player)
								}))))


    (describe "#moves->mills()" (fn [t]
          (t 
						(let [spaces [[:x 1 1] [:x 2 2]]
									moves [0 1 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 2]
									player 2
									]
							 {:given "a list of spaces and of current moves"
								:should "return a map of spaces to moves"
								:expected [false true]
								:actual (moves->mills spaces player)
								}))
          (t 
						(let [spaces [[1 1 :x] [:x 0 0]]
								  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 ]
									player 1
									]
							 {:given "a list of canditate-moves and of current moves"
								:should "return a map of spaces to moves"
								:expected [true false]
								:actual (moves->mills spaces player)
								}))))


    (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 "#mill?()" (fn [t]
        (t 
          (let [move 1
                player 1
								moves [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
                with-moves (partial with-mills moves)]
            {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
             :should "not be a mill"
             :expected false
             :actual (with-moves move player)
             }))
        (t 
          (let [move 3
                player 1
                moves [1 1 0]
                with-moves (partial with-mills moves)]
            {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
             :should "be a mill"
             :expected true
             :actual (with-moves move player)
             }))
        (t 
          (let [move 3
                player 1
                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 ]
                with-moves (partial with-mills moves)]
            {:given (string.format "a move of P%d:%d with moves %s" player move (table.concat moves ","))
             :should "be a mill"
             :expected true
             :actual (with-moves move player)
             }))))
    (test-end))))