summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/model/TableTest.java
blob: a806e14a085078f2f477bc521d18f7c8b0477544 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package jrummikub.model;

import static jrummikub.model.StoneColor.BLACK;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;

import org.junit.Before;
import org.junit.Test;

public class TableTest {
	Table testTable;

	@Before
	public void setup() {
		testTable = new Table();
	}

	@Test
	public void testIsValid() {
		testTable.drop(
				new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(
						1, BLACK))), new Position(0, 0));
		testTable.drop(
				new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED),
						new Stone(3, RED))), new Position(0, 0));
		assertTrue(testTable.isValid());

		testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
				new Position(0, 0));
		assertFalse(testTable.isValid());
	}

	@Test
	public void testEmptyIsValid() {
		assertTrue(testTable.isValid());
	}

	@Test
	@SuppressWarnings("unused")
	public void testPickUpStoneGroup() {
		Stone targetStone = new Stone(BLACK);
		testTable.drop(
				new StoneSet(Arrays.asList(new Stone(RED), targetStone, new Stone(1,
						BLACK))), new Position(0, 0));
		assertTrue(testTable.isValid());
		testTable.pickUpStone(targetStone);
		assertFalse(testTable.isValid());

		int counter = 0;
		for (Object i : testTable) {
			counter++;
		}
		assertEquals(1, counter);
	}

	@Test
	public void testPickLonelyStone() {
		Stone targetStone = new Stone(BLACK);
		testTable.drop(new StoneSet(targetStone), new Position(0, 0));
		testTable.pickUpStone(targetStone);
		assertEquals(0, testTable.getSize());
	}

	@Test
	public void testPickStoneFromEmptyTable() {
		Stone targetStone = new Stone(BLACK);
		testTable.pickUpStone(targetStone);
		assertEquals(0, testTable.getSize());
	}

	@Test
	public void testPickNonexistentStone() {
		Stone targetStone = new Stone(BLACK);
		Stone droppedStone = new Stone(RED);
		StoneSet set = new StoneSet(droppedStone);
		testTable.drop(set, new Position(0, 0));
		testTable.pickUpStone(targetStone);
		assertEquals(1, testTable.getSize());
		assertSame(testTable.findStoneSet(droppedStone), set);
	}

	@Test
	@SuppressWarnings("unused")
	public void testPickUpStoneRun() {
		Stone targetStone = new Stone(BLACK);
		testTable.drop(
				new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, new Stone(3,
						RED))), new Position(0, 0));
		assertTrue(testTable.isValid());
		testTable.pickUpStone(targetStone);
		assertFalse(testTable.isValid());

		int counter = 0;
		for (Object i : testTable) {
			counter++;
		}
		assertEquals(2, counter);
	}

	@Test
	public void testFindSet() {
		Stone targetStone = new Stone(BLACK);
		StoneSet testSet = new StoneSet(Arrays.asList(new Stone(1, RED),
				targetStone, new Stone(3, RED)));
		testTable.drop(testSet, new Position(0, 0));

		StoneSet foundSet = testTable.findStoneSet(targetStone);
		assertSame(testSet, foundSet);
	}
}