2011-04-30 14:47:42 +02:00
|
|
|
package jrummikub.model;
|
|
|
|
|
2011-05-03 19:06:13 +02:00
|
|
|
import static jrummikub.model.StoneColor.BLACK;
|
|
|
|
import static jrummikub.model.StoneColor.RED;
|
2011-05-05 15:57:13 +02:00
|
|
|
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;
|
2011-05-03 19:06:13 +02:00
|
|
|
|
2011-05-05 15:57:13 +02:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2011-05-03 19:06:13 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/**
|
|
|
|
* Tests for {@link Table}
|
|
|
|
*/
|
2011-04-30 14:47:42 +02:00
|
|
|
public class TableTest {
|
2011-05-03 19:06:13 +02:00
|
|
|
Table testTable;
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-03 19:06:13 +02:00
|
|
|
@Before
|
|
|
|
public void setup() {
|
|
|
|
testTable = new Table();
|
|
|
|
}
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-03 19:06:13 +02:00
|
|
|
@Test
|
|
|
|
public void testIsValid() {
|
2011-05-08 22:46:31 +02:00
|
|
|
testTable.drop(
|
2011-05-10 03:54:48 +02:00
|
|
|
new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK),
|
|
|
|
new Stone(1, BLACK))), new Position(0, 0));
|
2011-05-08 22:46:31 +02:00
|
|
|
testTable.drop(
|
2011-05-10 03:54:48 +02:00
|
|
|
new StoneSet(Arrays.asList(new Stone(1, RED),
|
|
|
|
new Stone(2, RED), new Stone(3, RED))), new Position(0,
|
|
|
|
0));
|
2011-05-03 19:06:13 +02:00
|
|
|
assertTrue(testTable.isValid());
|
2011-04-30 14:47:42 +02:00
|
|
|
|
2011-05-08 22:46:31 +02:00
|
|
|
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
|
|
|
|
new Position(0, 0));
|
2011-05-03 19:06:13 +02:00
|
|
|
assertFalse(testTable.isValid());
|
|
|
|
}
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-03 19:06:13 +02:00
|
|
|
@Test
|
|
|
|
public void testEmptyIsValid() {
|
|
|
|
assertTrue(testTable.isValid());
|
|
|
|
}
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-03 19:06:13 +02:00
|
|
|
@Test
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public void testPickUpStoneGroup() {
|
|
|
|
Stone targetStone = new Stone(BLACK);
|
2011-05-08 22:46:31 +02:00
|
|
|
testTable.drop(
|
2011-05-10 03:54:48 +02:00
|
|
|
new StoneSet(Arrays.asList(new Stone(RED), targetStone,
|
|
|
|
new Stone(1, BLACK))), new Position(0, 0));
|
2011-05-03 19:06:13 +02:00
|
|
|
assertTrue(testTable.isValid());
|
|
|
|
testTable.pickUpStone(targetStone);
|
|
|
|
assertFalse(testTable.isValid());
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-03 19:06:13 +02:00
|
|
|
int counter = 0;
|
|
|
|
for (Object i : testTable) {
|
|
|
|
counter++;
|
|
|
|
}
|
2011-05-03 19:06:16 +02:00
|
|
|
assertEquals(1, counter);
|
2011-05-03 19:06:13 +02:00
|
|
|
}
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-08 22:46:31 +02:00
|
|
|
@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());
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 00:33:30 +02:00
|
|
|
@Test
|
2011-05-09 00:33:31 +02:00
|
|
|
public void testPickStoneFromEmptyTable() {
|
2011-05-09 00:33:30 +02:00
|
|
|
Stone targetStone = new Stone(BLACK);
|
|
|
|
testTable.pickUpStone(targetStone);
|
|
|
|
assertEquals(0, testTable.getSize());
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 00:33:31 +02:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-03 19:06:13 +02:00
|
|
|
@Test
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public void testPickUpStoneRun() {
|
|
|
|
Stone targetStone = new Stone(BLACK);
|
2011-05-08 22:46:31 +02:00
|
|
|
testTable.drop(
|
2011-05-10 03:54:48 +02:00
|
|
|
new StoneSet(Arrays.asList(new Stone(1, RED), targetStone,
|
|
|
|
new Stone(3, RED))), new Position(0, 0));
|
2011-05-03 19:06:13 +02:00
|
|
|
assertTrue(testTable.isValid());
|
|
|
|
testTable.pickUpStone(targetStone);
|
|
|
|
assertFalse(testTable.isValid());
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-03 19:06:13 +02:00
|
|
|
int counter = 0;
|
|
|
|
for (Object i : testTable) {
|
|
|
|
counter++;
|
|
|
|
}
|
2011-05-03 19:06:16 +02:00
|
|
|
assertEquals(2, counter);
|
2011-05-03 19:06:13 +02:00
|
|
|
}
|
2011-05-08 22:46:31 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-04 19:41:41 +02:00
|
|
|
@Test
|
|
|
|
public void testFindSet() {
|
|
|
|
Stone targetStone = new Stone(BLACK);
|
2011-05-08 22:46:31 +02:00
|
|
|
StoneSet testSet = new StoneSet(Arrays.asList(new Stone(1, RED),
|
|
|
|
targetStone, new Stone(3, RED)));
|
|
|
|
testTable.drop(testSet, new Position(0, 0));
|
|
|
|
|
2011-05-04 19:41:41 +02:00
|
|
|
StoneSet foundSet = testTable.findStoneSet(targetStone);
|
|
|
|
assertSame(testSet, foundSet);
|
|
|
|
}
|
2011-04-30 14:47:42 +02:00
|
|
|
}
|