summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/model/StoneHeapTest.java113
1 files changed, 80 insertions, 33 deletions
diff --git a/test/jrummikub/model/StoneHeapTest.java b/test/jrummikub/model/StoneHeapTest.java
index ffe0cdf..811a2d1 100644
--- a/test/jrummikub/model/StoneHeapTest.java
+++ b/test/jrummikub/model/StoneHeapTest.java
@@ -1,54 +1,90 @@
package jrummikub.model;
+import static org.junit.Assert.*;
+
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.*;
-import static org.junit.Assert.*;
+import jrummikub.util.Pair;
+
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* Tests for {@link StoneHeap}
*/
+@RunWith(Theories.class)
public class StoneHeapTest {
- private StoneHeap testHeap;
- private GameSettings testSettings;
- /** */
- @Before
- public void createHeap() {
- testHeap = new StoneHeap(testSettings = new GameSettings());
+ private static Pair<GameSettings, StoneHeap> createHeap(GameSettings settings) {
+ return new Pair<GameSettings, StoneHeap>(settings, new StoneHeap(settings));
}
- private int calculateTotalNumberOfStones() {
+ /**
+ * @return the data points
+ */
+ @DataPoints
+ public static Pair<GameSettings, StoneHeap>[] createDataPoints() {
+ GameSettings testSettings1 = new GameSettings();
+
+ GameSettings testSettings2 = new GameSettings();
+ testSettings2.setJokerNumber(10);
+
+ GameSettings testSettings3 = new GameSettings();
+ testSettings3.setStoneSetNumber(1);
+
+ GameSettings testSettings4 = new GameSettings();
+ testSettings4.setJokerNumber(5);
+ testSettings4.setStoneSetNumber(5);
+
+ @SuppressWarnings("unchecked")
+ Pair<GameSettings, StoneHeap>[] ret = new Pair[4];
+ ret[0] = createHeap(testSettings1);
+ ret[1] = createHeap(testSettings2);
+ ret[2] = createHeap(testSettings3);
+ ret[3] = createHeap(testSettings4);
+
+ return ret;
+ }
+
+ private int calculateTotalNumberOfStones(GameSettings testSettings) {
int totalStones = testSettings.getHighestCard()
* testSettings.getStoneSetNumber()
- * testSettings.getStoneColors().size()
- + testSettings.getJokerNumber();
+ * testSettings.getStoneColors().size() + testSettings.getJokerNumber();
return totalStones;
}
/**
* Is the right number of Stones in heap?
+ *
+ * @param data
+ * data
*/
- @Test
- public void fullStoneHeap() {
- assertEquals(calculateTotalNumberOfStones(), testHeap.heap.size());
+ @Theory
+ public void fullStoneHeap(Pair<GameSettings, StoneHeap> data) {
+ assertEquals(calculateTotalNumberOfStones(data.getFirst()),
+ data.getSecond().heap.size());
}
/**
* Enough stones of each color in heap?
+ *
+ * @param data
+ * data
*/
- @Test
- public void fullColor() {
- int stonesOfAColor = testSettings.getHighestCard()
- * testSettings.getStoneSetNumber();
+ @Theory
+ public void fullColor(Pair<GameSettings, StoneHeap> data) {
+ int stonesOfAColor = data.getFirst().getHighestCard()
+ * data.getFirst().getStoneSetNumber();
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
counters.put(c, 0);
}
- for (Stone i : testHeap.heap) {
+ for (Stone i : data.getSecond().heap) {
if (i.isJoker())
continue;
int count = counters.get(i.getColor());
@@ -61,29 +97,40 @@ public class StoneHeapTest {
/**
* Enough Jokers?
+ *
+ * @param data
+ * data
*/
- @Test
- public void fullJoker() {
+ @Theory
+ public void fullJoker(Pair<GameSettings, StoneHeap> data) {
int countJoker = 0;
- for (Stone i : testHeap.heap) {
+ for (Stone i : data.getSecond().heap) {
if (i.isJoker())
countJoker++;
}
- assertEquals(testSettings.getJokerNumber(), countJoker);
+ assertEquals(data.getFirst().getJokerNumber(), countJoker);
}
- /** */
- @Test
- public void drawStoneTest() {
- assertNotNull(testHeap.drawStone());
- assertEquals(calculateTotalNumberOfStones() - 1, testHeap.heap.size());
+ /**
+ * @param data
+ * data
+ */
+ @Theory
+ public void drawStoneTest(Pair<GameSettings, StoneHeap> data) {
+ assertNotNull(data.getSecond().drawStone());
+ assertEquals(calculateTotalNumberOfStones(data.getFirst()) - 1,
+ data.getSecond().heap.size());
}
- /** */
- @Test
- public void drawStonesTest() {
- List<Stone> testStones = testHeap.drawStones(5);
+ /**
+ * @param data
+ * data
+ */
+ @Theory
+ public void drawStonesTest(Pair<GameSettings, StoneHeap> data) {
+ List<Stone> testStones = data.getSecond().drawStones(5);
assertEquals(5, testStones.size());
- assertEquals(calculateTotalNumberOfStones() - 5, testHeap.heap.size());
+ assertEquals(calculateTotalNumberOfStones(data.getFirst()) - 5,
+ data.getSecond().heap.size());
}
}