summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/model/StoneHeapTest.java
blob: 9fd375a15d5b684932ea605df74b012bb54ee335 (plain)
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
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;

	/** */
	@Before
	public void createHeap() {
		testHeap = new StoneHeap();
	}

	/**
	 * Is the right number of Stones in heap?
	 */
	@Test
	public void fullStoneHeap() {
		assertEquals(106, testHeap.heap.size());
	}

	/**
	 * Enough stones of each color in heap?
	 */
	@Test
	public void fullColor() {
		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(26, (long) counters.get(c));
		}
	}

	/**
	 * Enough Jokers?
	 */
	@Test
	public void fullJoker() {
		int countJoker = 0;
		for (Stone i : testHeap.heap) {
			if (i.isJoker())
				countJoker++;
		}
		assertEquals(2, countJoker);
	}

	/** */
	@Test
	public void drawStoneTest() {
		assertNotNull(testHeap.drawStone());
		assertEquals(105, testHeap.heap.size());
	}

	/** */
	@Test
	public void drawStonesTest() {
		List<Stone> testStones = testHeap.drawStones(5);
		assertEquals(5, testStones.size());
		assertEquals(101, testHeap.heap.size());
	}
}