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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
package jrummikub.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import jrummikub.util.Pair;
import static jrummikub.model.StoneColor.*;
import static jrummikub.model.StoneSet.Type.*;
import org.junit.*;
import static org.junit.Assert.*;
/**
* Tests for {@link StoneSet}
*/
public class StoneSetTest {
private void assertSet(StoneSet.Type expectedType, Integer expectedValue,
List<Stone> stones) {
StoneSet set = new StoneSet(stones);
assertSame(expectedType, set.classify().getFirst());
assertEquals(expectedValue, set.classify().getSecond());
}
// valid+point count
/** */
@Test
public void doubleJoker() {
// 3 Stones
// JJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK)));
// JZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(BLACK)));
// ZJJ
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(BLACK)));
// 4 Stones
// JJZZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK), new Stone(1, RED)));
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(3, RED), new Stone(4, RED)));
// ZZJJ
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(BLACK), new Stone(RED)));
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(BLACK), new Stone(RED)));
// ZJZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(1, BLACK), new Stone(RED)));
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(3, RED), new Stone(BLACK)));
// JZJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(BLACK), new Stone(1, RED)));
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(BLACK), new Stone(4, RED)));
// JZZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(1, RED), new Stone(BLACK)));
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(3, RED), new Stone(BLACK)));
// ZJJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(RED), new Stone(1, BLACK)));
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(BLACK), new Stone(4, RED)));
}
/** */
@Test
public void groups() {
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(1, BLUE)));
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(1, BLUE), new Stone(1, ORANGE)));
}
/** */
@Test
public void runs() {
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(3, RED)));
assertSet(RUN, 22, Arrays.asList(new Stone(4, BLUE),
new Stone(5, BLUE), new Stone(6, BLUE), new Stone(7, BLUE)));
}
/** */
@Test
public void singleJoker() {
// ZJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(1, BLACK)));
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(3, RED)));
// JZZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, RED),
new Stone(1, BLACK)));
assertSet(RUN, 6, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(3, RED)));
// ZZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(BLACK)));
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(RED)));
}
// invalid
/** */
@Test
public void outOfBounds() {
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(1, RED),
new Stone(2, RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(12, RED), new Stone(13,
RED), new Stone(RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, RED), new Stone(2, RED)));
}
/** */
@Test
public void sameColor() {
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED),
new Stone(1, RED), new Stone(1, BLUE)));
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
BLUE), new Stone(1, BLACK), new Stone(1, ORANGE),
new Stone(RED)));
}
/** */
@Test
public void incorrectOrder() {
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(6, RED), new Stone(5, RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(6, RED), new Stone(RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(RED),
new Stone(5, RED)));
}
/** */
@Test
public void otherInvalid() {
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(5, RED), new Stone(7, RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(5,
BLUE), new Stone(6, RED)));
assertSet(INVALID, 0,
Arrays.asList(new Stone(4, RED), new Stone(5, RED)));
assertSet(INVALID, 0, Arrays.asList(new Stone(4, BLUE), new Stone(5,
RED), new Stone(6, RED)));
// Regression test:
assertSet(INVALID, 0, Arrays.asList(new Stone(12, ORANGE), new Stone(
12, BLACK), new Stone(7, BLUE)));
}
/** */
@Test
public void manyJokersValid() {
assertSet(GROUP, 3 * 13, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED)));
assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED)));
assertSet(RUN, 13 + 12 + 11 + 10 + 9, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED)));
assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(12, RED)));
}
/** */
@Test
public void manyJokersInvalid() {
List<Stone> stones = new ArrayList<Stone>();
for (int i = 0; i < 14; i++) {
stones.add(new Stone(RED));
}
assertSet(INVALID, 0, stones);
}
// invalid Split
/** */
@Test
public void testSplitInvalidLow() {
StoneSet testSet = createTestSet();
assertNull(testSet.splitAt(0).getFirst());
}
/** */
@Test
public void testSplitInvalidHigh() {
StoneSet testSet = createTestSet();
assertNull(testSet.splitAt(3).getSecond());
}
// valid Split
/** */
@Test
public void testSplitValid() {
StoneSet testSet = createTestSet();
Pair<StoneSet, StoneSet> newSets = testSet.splitAt(1);
// Sets have right size
assertEquals(1, newSets.getFirst().size());
assertEquals(2, newSets.getSecond().size());
// Set have right Stones
assertSame(testSet.get(0), newSets.getFirst().get(0));
assertSame(testSet.get(1), newSets.getSecond().get(0));
assertSame(testSet.get(2), newSets.getSecond().get(1));
}
private StoneSet createTestSet() {
List<Stone> stones = new ArrayList<Stone>();
stones.add(new Stone(1, BLUE));
stones.add(new Stone(1, RED));
stones.add(new Stone(1, BLACK));
StoneSet testSet = new StoneSet(stones);
return testSet;
}
// join
/** */
@Test
public void testJoin() {
StoneSet testSet = createTestSet();
StoneSet secondSet = new StoneSet(new Stone(2, BLUE));
StoneSet joinedSet = testSet.join(secondSet);
// Sets have right size
assertEquals(4, joinedSet.size());
// Set have right Stones
assertSame(testSet.get(0), joinedSet.get(0));
assertSame(testSet.get(1), joinedSet.get(1));
assertSame(testSet.get(2), joinedSet.get(2));
assertSame(secondSet.get(0), joinedSet.get(3));
}
// iterator
/** */
@Test
public void testIterator() {
StoneSet testSet = createTestSet();
int i = 0;
for (Stone stone : testSet) {
assertSame(stone, testSet.get(i));
i++;
}
assertEquals(i, testSet.size());
}
/**
* String for Testing
*/
@Test
public void testToString() {
StoneSet testSet = new StoneSet(Arrays.asList(new Stone(2, BLUE),
new Stone(3, BLUE), new Stone(4, BLUE)));
assertEquals(
"StoneSet[Stone[value=2,color=BLUE],Stone[value=3,color=BLUE],Stone[value=4,color=BLUE]]",
testSet.toString());
}
}
|