summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/model/StoneSetTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub/model/StoneSetTest.java')
-rw-r--r--test/jrummikub/model/StoneSetTest.java182
1 files changed, 125 insertions, 57 deletions
diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java
index f53163e..a5c44f0 100644
--- a/test/jrummikub/model/StoneSetTest.java
+++ b/test/jrummikub/model/StoneSetTest.java
@@ -1,91 +1,136 @@
package jrummikub.model;
+import static jrummikub.model.StoneColor.*;
+import static jrummikub.model.StoneSet.Type.*;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashSet;
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.*;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for {@link StoneSet}
*/
public class StoneSetTest {
+ private GameSettings defaultSettings = new GameSettings();
+ private GameSettings moreColorSettings = new GameSettings();
+ private GameSettings lessColorSettings = new GameSettings();
+ private GameSettings higherValueSettings = new GameSettings();
+ private GameSettings lowerValueSettings = new GameSettings();
+
+ /** */
+ @Before
+ public void setUpSettings() {
+ moreColorSettings.setStoneColors(EnumSet.allOf(StoneColor.class));
+ lessColorSettings.setStoneColors(new HashSet<StoneColor>(Arrays.asList(
+ StoneColor.BLUE, StoneColor.RED, StoneColor.BLACK)));
+ higherValueSettings.setHighestCard(17);
+ lowerValueSettings.setHighestCard(10);
+ }
private void assertSet(StoneSet.Type expectedType, Integer expectedValue,
- List<Stone> stones) {
+ List<Stone> stones, GameSettings settings) {
StoneSet set = new StoneSet(stones);
- assertSame(expectedType, set.classify().getFirst());
- assertEquals(expectedValue, set.classify().getSecond());
+ assertSame(expectedType, set.classify(settings).getFirst());
+ assertEquals(expectedValue, set.classify(settings).getSecond());
}
// valid+point count
/** */
@Test
- public void doubleJoker() {
+ public void doubleJokerValid() {
// 3 Stones
// JJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(BLACK),
- new Stone(1, BLACK)));
+ new Stone(1, BLACK)), defaultSettings);
// JZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
- new Stone(BLACK)));
+ new Stone(BLACK)), defaultSettings);
// ZJJ
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
- new Stone(BLACK)));
+ new Stone(BLACK)), defaultSettings);
+ assertSet(RUN, 33, Arrays.asList(new Stone(10, RED), new Stone(RED),
+ new Stone(BLACK)), defaultSettings);
+ assertSet(GROUP, 30, Arrays.asList(new Stone(10, RED), new Stone(RED),
+ new Stone(BLACK)), lowerValueSettings);
+ assertSet(GROUP, 39, Arrays.asList(new Stone(13, RED), new Stone(RED),
+ new Stone(BLACK)), defaultSettings);
+ assertSet(RUN, 42, Arrays.asList(new Stone(13, RED), new Stone(RED),
+ new Stone(BLACK)), higherValueSettings);
// 4 Stones
// JJZZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(BLACK),
- new Stone(1, BLACK), new Stone(1, RED)));
+ new Stone(1, BLACK), new Stone(1, RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(BLACK),
- new Stone(3, RED), new Stone(4, RED)));
+ new Stone(3, RED), new Stone(4, RED)), defaultSettings);
// ZZJJ
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
- new Stone(BLACK), new Stone(RED)));
+ new Stone(BLACK), new Stone(RED)), defaultSettings);
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
- new Stone(1, BLACK), new Stone(BLACK), new Stone(RED)));
+ new Stone(1, BLACK), new Stone(BLACK), new Stone(RED)),
+ defaultSettings);
// ZJZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
- new Stone(1, BLACK), new Stone(RED)));
+ new Stone(1, BLACK), new Stone(RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
- new Stone(3, RED), new Stone(BLACK)));
+ new Stone(3, RED), new Stone(BLACK)), defaultSettings);
// JZJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
- new Stone(BLACK), new Stone(1, RED)));
+ new Stone(BLACK), new Stone(1, RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
- new Stone(BLACK), new Stone(4, RED)));
+ new Stone(BLACK), new Stone(4, RED)), defaultSettings);
// JZZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
- new Stone(1, RED), new Stone(BLACK)));
+ new Stone(1, RED), new Stone(BLACK)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
- new Stone(3, RED), new Stone(BLACK)));
+ new Stone(3, RED), new Stone(BLACK)), defaultSettings);
// ZJJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
- new Stone(RED), new Stone(1, BLACK)));
+ new Stone(RED), new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
- new Stone(BLACK), new Stone(4, RED)));
+ new Stone(BLACK), new Stone(4, RED)), defaultSettings);
+ // More than 4 stones
+ assertSet(GROUP, 6, Arrays.asList(new Stone(1, RED),
+ new Stone(1, BLUE), new Stone(1, GREEN), new Stone(1, BLACK),
+ new Stone(BLACK), new Stone(RED)), moreColorSettings);
}
/** */
@Test
public void groups() {
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
- new Stone(1, BLACK), new Stone(1, BLUE)));
+ new Stone(1, BLACK), new Stone(1, BLUE)), defaultSettings);
+ assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
+ new Stone(1, BLACK), new Stone(1, BLUE)), lessColorSettings);
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
- new Stone(1, BLACK), new Stone(1, BLUE), new Stone(1, ORANGE)));
+ new Stone(1, BLACK), new Stone(1, BLUE), new Stone(1, ORANGE)),
+ defaultSettings);
+ assertSet(GROUP, 6, Arrays.asList(new Stone(1, RED),
+ new Stone(1, GREEN), new Stone(1, WHITE), new Stone(1, BLACK),
+ new Stone(1, BLUE), new Stone(1, ORANGE)), moreColorSettings);
}
/** */
@Test
public void runs() {
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
- new Stone(3, RED)));
+ new Stone(3, RED)), defaultSettings);
+ assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
+ new Stone(3, RED)), lowerValueSettings);
+ assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
+ new Stone(3, RED)), higherValueSettings);
assertSet(RUN, 22, Arrays.asList(new Stone(4, BLUE),
- new Stone(5, BLUE), new Stone(6, BLUE), new Stone(7, BLUE)));
+ new Stone(5, BLUE), new Stone(6, BLUE), new Stone(7, BLUE)),
+ defaultSettings);
+ assertSet(RUN, 42, Arrays.asList(new Stone(13, RED),
+ new Stone(14, RED), new Stone(15, RED)), higherValueSettings);
}
/** */
@@ -93,84 +138,107 @@ public class StoneSetTest {
public void singleJoker() {
// ZJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
- new Stone(1, BLACK)));
+ new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
- new Stone(3, RED)));
+ new Stone(3, RED)), defaultSettings);
// JZZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, RED),
- new Stone(1, BLACK)));
+ new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(RED), new Stone(2, RED),
- new Stone(3, RED)));
+ new Stone(3, RED)), defaultSettings);
// ZZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
- new Stone(1, BLACK), new Stone(BLACK)));
+ new Stone(1, BLACK), new Stone(BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
- new Stone(RED)));
+ new Stone(RED)), defaultSettings);
+ assertSet(RUN, 39, Arrays.asList(new Stone(12, RED),
+ new Stone(13, RED), new Stone(RED)), higherValueSettings);
}
// invalid
/** */
@Test
+ public void doubleJokerInvalid() {
+ assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK),
+ new Stone(1, BLACK), new Stone(1, RED)), lessColorSettings);
+ // More than 4 stones
+ assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
+ BLUE), new Stone(1, GREEN), new Stone(1, BLACK), new Stone(1,
+ VIOLET), new Stone(1, ORANGE), new Stone(1, BROWN), new Stone(
+ BLACK), new Stone(RED)), moreColorSettings);
+ }
+
+ /** */
+ @Test
public void outOfBounds() {
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(1, RED),
- new Stone(2, RED)));
+ new Stone(2, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(12, RED), new Stone(13,
- RED), new Stone(RED)));
+ RED), new Stone(RED)), defaultSettings);
+ assertSet(INVALID, 0, Arrays.asList(new Stone(9, RED), new Stone(10,
+ RED), new Stone(RED)), lowerValueSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK),
- new Stone(1, RED), new Stone(2, RED)));
+ new Stone(1, RED), new Stone(2, RED)), defaultSettings);
}
/** */
@Test
public void sameColor() {
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED),
- new Stone(1, RED), new Stone(1, BLUE)));
+ new Stone(1, RED), new Stone(1, BLUE)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
BLUE), new Stone(1, BLACK), new Stone(1, ORANGE),
- new Stone(RED)));
+ new Stone(RED)), defaultSettings);
+ assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
+ BLUE), new Stone(1, GREEN), new Stone(1, BLACK), new Stone(1,
+ VIOLET), new Stone(1, WHITE), new Stone(1, ORANGE), new Stone(
+ 1, BROWN), new Stone(RED)), moreColorSettings);
}
/** */
@Test
public void incorrectOrder() {
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
- new Stone(6, RED), new Stone(5, RED)));
+ new Stone(6, RED), new Stone(5, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
- new Stone(6, RED), new Stone(RED)));
+ new Stone(6, RED), new Stone(RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(RED),
- new Stone(5, RED)));
+ new Stone(5, RED)), defaultSettings);
}
/** */
@Test
public void otherInvalid() {
-
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
- new Stone(5, RED), new Stone(7, RED)));
+ new Stone(5, RED), new Stone(7, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(5,
- BLUE), new Stone(6, RED)));
+ BLUE), new Stone(6, RED)), defaultSettings);
assertSet(INVALID, 0,
- Arrays.asList(new Stone(4, RED), new Stone(5, RED)));
+ Arrays.asList(new Stone(4, RED), new Stone(5, RED)),
+ defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, BLUE), new Stone(5,
- RED), new Stone(6, RED)));
+ RED), new Stone(6, RED)), defaultSettings);
// Regression test:
assertSet(INVALID, 0, Arrays.asList(new Stone(12, ORANGE), new Stone(
- 12, BLACK), new Stone(7, BLUE)));
+ 12, BLACK), new Stone(7, BLUE)), defaultSettings);
}
/** */
@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)));
+ assertSet(GROUP, 3 * 13,
+ Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED)),
+ defaultSettings);
+ assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED), new Stone(RED),
+ new Stone(RED), new Stone(RED)), defaultSettings);
+ assertSet(RUN, 13 + 12 + 11 + 10 + 9,
+ Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED),
+ new Stone(RED), new Stone(RED)), defaultSettings);
+ assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED), new Stone(RED),
+ new Stone(RED), new Stone(RED), new Stone(12, RED)),
+ defaultSettings);
}
-
+
/** */
@Test
public void manyJokersInvalid() {
@@ -178,7 +246,7 @@ public class StoneSetTest {
for (int i = 0; i < 14; i++) {
stones.add(new Stone(RED));
}
- assertSet(INVALID, 0, stones);
+ assertSet(INVALID, 0, stones, defaultSettings);
}
// invalid Split