2011-04-30 14:47:42 +02:00
|
|
|
package jrummikub.model;
|
|
|
|
|
2011-05-03 19:06:13 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
|
|
|
import static jrummikub.model.StoneColor.BLACK;
|
|
|
|
import static jrummikub.model.StoneColor.RED;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
import jrummikub.model.Table;
|
|
|
|
|
2011-04-30 14:47:42 +02:00
|
|
|
public class TableTest {
|
2011-05-03 19:06:13 +02:00
|
|
|
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());
|
2011-04-30 14:47:42 +02:00
|
|
|
|
2011-05-03 19:06:13 +02:00
|
|
|
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++;
|
|
|
|
}
|
2011-05-03 19:06:16 +02:00
|
|
|
assertEquals(1, counter);
|
2011-05-03 19:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public void testPickUpStoneRun() {
|
|
|
|
Stone targetStone = new Stone(BLACK);
|
|
|
|
testTable.drop(new StoneSet(Arrays.asList(new Stone(1, RED), targetStone,
|
2011-05-03 19:06:16 +02:00
|
|
|
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());
|
|
|
|
|
|
|
|
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-04 19:41:41 +02:00
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
2011-04-30 14:47:42 +02:00
|
|
|
}
|