summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/turn
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-21 00:04:16 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-21 00:04:16 +0200
commitf5cff88ec9177b23dc8979aa9645a427a78c6f46 (patch)
tree5192fc950c594b9772bf28b1e8e3d712817c3b09 /test/jrummikub/control/turn
parent1ba3c9758394f551aa913df52852c19e7e6c6187 (diff)
downloadJRummikub-f5cff88ec9177b23dc8979aa9645a427a78c6f46.tar
JRummikub-f5cff88ec9177b23dc8979aa9645a427a78c6f46.zip
Major refactoring of RoundControl and TurnControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@516 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub/control/turn')
-rw-r--r--test/jrummikub/control/turn/TurnControlTest.java100
1 files changed, 88 insertions, 12 deletions
diff --git a/test/jrummikub/control/turn/TurnControlTest.java b/test/jrummikub/control/turn/TurnControlTest.java
index 98b1852..9e89a57 100644
--- a/test/jrummikub/control/turn/TurnControlTest.java
+++ b/test/jrummikub/control/turn/TurnControlTest.java
@@ -182,12 +182,13 @@ public class TurnControlTest {
eventFired = false;
mockTimer.timerRunning = true;
- testControl.getEndOfTurnEvent().add(new IListener3<IHand, ITable, ITable>() {
- @Override
- public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
- eventFired = true;
- }
- });
+ testControl.getEndOfTurnEvent().add(
+ new IListener3<IHand, ITable, ITable>() {
+ @Override
+ public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
+ eventFired = true;
+ }
+ });
mockView.playerPanel.endTurnEvent.emit();
@@ -204,12 +205,13 @@ public class TurnControlTest {
eventFired = false;
mockTimer.timerRunning = true;
- testControl.getEndOfTurnEvent().add(new IListener3<IHand, ITable, ITable>() {
- @Override
- public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
- eventFired = true;
- }
- });
+ testControl.getEndOfTurnEvent().add(
+ new IListener3<IHand, ITable, ITable>() {
+ @Override
+ public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
+ eventFired = true;
+ }
+ });
mockTimer.timeRunOutEvent.emit();
@@ -1013,4 +1015,78 @@ public class TurnControlTest {
assertEquals(expected, handStones);
}
+ /** */
+ @Test
+ public void testTableDifference() {
+ MockTable oldTable = new MockTable();
+ MockTable newTable = new MockTable();
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne));
+ StoneSet oldSet2 = new StoneSet(blueTwo);
+ oldTable.drop(oldSet1, new Position(0, 0));
+ oldTable.drop(oldSet2, new Position(0, 0));
+ StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour));
+ StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree));
+ newTable.drop(newSet1, new Position(0, 0));
+ newTable.drop(newSet2, new Position(0, 0));
+
+ Set<Stone> expectedStones = new HashSet<Stone>();
+ expectedStones.add(blueThree);
+ expectedStones.add(blueFour);
+
+ Set<Stone> stones = AbstractTurnControl.tableDifference(oldTable, newTable);
+
+ assertTrue(expectedStones.containsAll(stones));
+ assertTrue(stones.containsAll(expectedStones));
+ }
+
+ /** */
+ @Test
+ public void testTableSetDifference() {
+ ITable oldTable = new AccessibleTable();
+ Stone blueOne = new Stone(1, BLUE);
+ Stone redOne = new Stone(1, RED);
+ Stone blackOne = new Stone(1, BLACK);
+ Stone orangeOne = new Stone(1, ORANGE);
+ Stone blueTwo = new Stone(2, BLUE);
+ Stone blueThree = new Stone(3, BLUE);
+ Stone blueFour = new Stone(4, BLUE);
+ StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
+ orangeOne));
+ StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour));
+ oldTable.drop(oldSet1, new Position(0, 0));
+ oldTable.drop(oldSet2, new Position(0, 0));
+ ITable newTable = (Table) oldTable.clone();
+ List<StoneSet> newSets = AbstractTurnControl.tableSetDifference(oldTable,
+ newTable);
+ List<StoneSet> vanishedSets = AbstractTurnControl.tableSetDifference(
+ newTable, oldTable);
+
+ assertTrue(newSets.isEmpty());
+ assertTrue(vanishedSets.isEmpty());
+
+ newTable.pickUp(oldSet2);
+ newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position(
+ 0, 0));
+ newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable);
+ vanishedSets = AbstractTurnControl.tableSetDifference(newTable, oldTable);
+
+ assertFalse(newSets.isEmpty());
+ assertFalse(vanishedSets.isEmpty());
+ assertEquals(1, newSets.size());
+ assertEquals(1, vanishedSets.size());
+
+ Stone redTwo = new Stone(2, RED);
+ Stone redThree = new Stone(3, RED);
+ Stone redFour = new Stone(4, RED);
+ StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour));
+ ITable newTable2 = (Table) oldTable.clone();
+ newTable2.drop(oldSet3, new Position(0, 0));
+ newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2);
+ vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, oldTable);
+
+ assertFalse(newSets.isEmpty());
+ assertTrue(vanishedSets.isEmpty());
+ assertEquals(1, newSets.size());
+ }
+
}