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
|
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 org.junit.*;
import static org.junit.Assert.*;
public class StoneSetTest {
// Is Valid-Test
// valid
public void assertSet(boolean valid, List<Stone> stones) {
StoneSet set = new StoneSet(stones);
assertTrue(valid == set.isValid());
}
@Test
public void doubleJoker() {
assertSet(true, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK)));
}
@Test
public void groups() {
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
new Stone(1, BLUE)));
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
new Stone(1, BLUE), new Stone(1, ORANGE)));
}
@Test
public void runs() {
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(3, RED)));
assertSet(true, Arrays.asList(new Stone(4, BLUE), new Stone(5, BLUE),
new Stone(6, BLUE)));
}
@Test
public void singleJoker() {
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
new Stone(RED)));
assertSet(true, Arrays.asList(new Stone(2, RED), new Stone(3, RED),
new Stone(BLACK)));
}
// invalid
@Test
public void outOfBounds() {
assertSet(false, Arrays.asList(new Stone(RED), new Stone(1, RED),
new Stone(2, RED)));
assertSet(false, Arrays.asList(new Stone(12, RED), new Stone(13, RED),
new Stone(RED)));
assertSet(false, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, RED), new Stone(2, RED)));
}
@Test
public void sameColor() {
assertSet(false, Arrays.asList(new Stone(1, RED), new Stone(1, RED),
new Stone(1, BLUE)));
assertSet(false, 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(false, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
new Stone(5, RED)));
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
new Stone(RED)));
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(RED),
new Stone(5, RED)));
}
@Test
public void otherInvalid() {
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, RED),
new Stone(7, RED)));
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, BLUE),
new Stone(6, RED)));
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, RED)));
assertSet(false, Arrays.asList(new Stone(4, BLUE), new Stone(5, RED),
new Stone(6, RED)));
}
// invalid Split
@Test(expected = IndexOutOfBoundsException.class)
public void testSplitInvalidLow() {
StoneSet testSet = createTestSet();
testSet.splitAt(0);
}
@Test(expected = IndexOutOfBoundsException.class)
public void testSplitInvalidHigh() {
StoneSet testSet = createTestSet();
testSet.splitAt(3);
}
// 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());
}
}
|