Test different stone heap configurations with JUnit theories; allow creating stone heaps with different stone set numbers
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@329 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
1660736239
commit
55088e15a1
2 changed files with 81 additions and 34 deletions
|
@ -25,7 +25,7 @@ public class StoneHeap {
|
||||||
public StoneHeap(GameSettings gameSettings) {
|
public StoneHeap(GameSettings gameSettings) {
|
||||||
heap = new ArrayList<Stone>();
|
heap = new ArrayList<Stone>();
|
||||||
for (int i = 1; i <= 13; i++) {
|
for (int i = 1; i <= 13; i++) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) {
|
||||||
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
||||||
heap.add(new Stone(i, c));
|
heap.add(new Stone(i, c));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,90 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.*;
|
import jrummikub.util.Pair;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
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}
|
* Tests for {@link StoneHeap}
|
||||||
*/
|
*/
|
||||||
|
@RunWith(Theories.class)
|
||||||
public class StoneHeapTest {
|
public class StoneHeapTest {
|
||||||
private StoneHeap testHeap;
|
|
||||||
private GameSettings testSettings;
|
|
||||||
|
|
||||||
/** */
|
private static Pair<GameSettings, StoneHeap> createHeap(GameSettings settings) {
|
||||||
@Before
|
return new Pair<GameSettings, StoneHeap>(settings, new StoneHeap(settings));
|
||||||
public void createHeap() {
|
|
||||||
testHeap = new StoneHeap(testSettings = new GameSettings());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
int totalStones = testSettings.getHighestCard()
|
||||||
* testSettings.getStoneSetNumber()
|
* testSettings.getStoneSetNumber()
|
||||||
* testSettings.getStoneColors().size()
|
* testSettings.getStoneColors().size() + testSettings.getJokerNumber();
|
||||||
+ testSettings.getJokerNumber();
|
|
||||||
return totalStones;
|
return totalStones;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the right number of Stones in heap?
|
* Is the right number of Stones in heap?
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* data
|
||||||
*/
|
*/
|
||||||
@Test
|
@Theory
|
||||||
public void fullStoneHeap() {
|
public void fullStoneHeap(Pair<GameSettings, StoneHeap> data) {
|
||||||
assertEquals(calculateTotalNumberOfStones(), testHeap.heap.size());
|
assertEquals(calculateTotalNumberOfStones(data.getFirst()),
|
||||||
|
data.getSecond().heap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enough stones of each color in heap?
|
* Enough stones of each color in heap?
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* data
|
||||||
*/
|
*/
|
||||||
@Test
|
@Theory
|
||||||
public void fullColor() {
|
public void fullColor(Pair<GameSettings, StoneHeap> data) {
|
||||||
int stonesOfAColor = testSettings.getHighestCard()
|
int stonesOfAColor = data.getFirst().getHighestCard()
|
||||||
* testSettings.getStoneSetNumber();
|
* data.getFirst().getStoneSetNumber();
|
||||||
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
|
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
|
||||||
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
||||||
counters.put(c, 0);
|
counters.put(c, 0);
|
||||||
}
|
}
|
||||||
for (Stone i : testHeap.heap) {
|
for (Stone i : data.getSecond().heap) {
|
||||||
if (i.isJoker())
|
if (i.isJoker())
|
||||||
continue;
|
continue;
|
||||||
int count = counters.get(i.getColor());
|
int count = counters.get(i.getColor());
|
||||||
|
@ -61,29 +97,40 @@ public class StoneHeapTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enough Jokers?
|
* Enough Jokers?
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* data
|
||||||
*/
|
*/
|
||||||
@Test
|
@Theory
|
||||||
public void fullJoker() {
|
public void fullJoker(Pair<GameSettings, StoneHeap> data) {
|
||||||
int countJoker = 0;
|
int countJoker = 0;
|
||||||
for (Stone i : testHeap.heap) {
|
for (Stone i : data.getSecond().heap) {
|
||||||
if (i.isJoker())
|
if (i.isJoker())
|
||||||
countJoker++;
|
countJoker++;
|
||||||
}
|
}
|
||||||
assertEquals(testSettings.getJokerNumber(), countJoker);
|
assertEquals(data.getFirst().getJokerNumber(), countJoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
@Test
|
* @param data
|
||||||
public void drawStoneTest() {
|
* data
|
||||||
assertNotNull(testHeap.drawStone());
|
*/
|
||||||
assertEquals(calculateTotalNumberOfStones() - 1, testHeap.heap.size());
|
@Theory
|
||||||
|
public void drawStoneTest(Pair<GameSettings, StoneHeap> data) {
|
||||||
|
assertNotNull(data.getSecond().drawStone());
|
||||||
|
assertEquals(calculateTotalNumberOfStones(data.getFirst()) - 1,
|
||||||
|
data.getSecond().heap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
@Test
|
* @param data
|
||||||
public void drawStonesTest() {
|
* data
|
||||||
List<Stone> testStones = testHeap.drawStones(5);
|
*/
|
||||||
|
@Theory
|
||||||
|
public void drawStonesTest(Pair<GameSettings, StoneHeap> data) {
|
||||||
|
List<Stone> testStones = data.getSecond().drawStones(5);
|
||||||
assertEquals(5, testStones.size());
|
assertEquals(5, testStones.size());
|
||||||
assertEquals(calculateTotalNumberOfStones() - 5, testHeap.heap.size());
|
assertEquals(calculateTotalNumberOfStones(data.getFirst()) - 5,
|
||||||
|
data.getSecond().heap.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue