diff options
Diffstat (limited to 'test/jrummikub/control/turn')
-rw-r--r-- | test/jrummikub/control/turn/TurnControlTest.java | 100 |
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()); + } + } |