
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@327 72836036-5685-4462-b002-a69064685172
89 lines
2 KiB
Java
89 lines
2 KiB
Java
package jrummikub.model;
|
|
|
|
import java.util.EnumSet;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.junit.*;
|
|
import static org.junit.Assert.*;
|
|
|
|
/**
|
|
* Tests for {@link StoneHeap}
|
|
*/
|
|
public class StoneHeapTest {
|
|
private StoneHeap testHeap;
|
|
private GameSettings testSettings;
|
|
|
|
/** */
|
|
@Before
|
|
public void createHeap() {
|
|
testHeap = new StoneHeap(testSettings = new GameSettings());
|
|
}
|
|
|
|
private int calculateTotalNumberOfStones() {
|
|
int totalStones = testSettings.getHighestCard()
|
|
* testSettings.getStoneSetNumber()
|
|
* testSettings.getStoneColors().size()
|
|
+ testSettings.getJokerNumber();
|
|
return totalStones;
|
|
}
|
|
|
|
/**
|
|
* Is the right number of Stones in heap?
|
|
*/
|
|
@Test
|
|
public void fullStoneHeap() {
|
|
assertEquals(calculateTotalNumberOfStones(), testHeap.heap.size());
|
|
}
|
|
|
|
/**
|
|
* Enough stones of each color in heap?
|
|
*/
|
|
@Test
|
|
public void fullColor() {
|
|
int stonesOfAColor = testSettings.getHighestCard()
|
|
* testSettings.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) {
|
|
if (i.isJoker())
|
|
continue;
|
|
int count = counters.get(i.getColor());
|
|
counters.put(i.getColor(), count + 1);
|
|
}
|
|
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
|
assertEquals(stonesOfAColor, (long) counters.get(c));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enough Jokers?
|
|
*/
|
|
@Test
|
|
public void fullJoker() {
|
|
int countJoker = 0;
|
|
for (Stone i : testHeap.heap) {
|
|
if (i.isJoker())
|
|
countJoker++;
|
|
}
|
|
assertEquals(testSettings.getJokerNumber(), countJoker);
|
|
}
|
|
|
|
/** */
|
|
@Test
|
|
public void drawStoneTest() {
|
|
assertNotNull(testHeap.drawStone());
|
|
assertEquals(calculateTotalNumberOfStones() - 1, testHeap.heap.size());
|
|
}
|
|
|
|
/** */
|
|
@Test
|
|
public void drawStonesTest() {
|
|
List<Stone> testStones = testHeap.drawStones(5);
|
|
assertEquals(5, testStones.size());
|
|
assertEquals(calculateTotalNumberOfStones() - 5, testHeap.heap.size());
|
|
}
|
|
}
|