From f5cff88ec9177b23dc8979aa9645a427a78c6f46 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 00:04:16 +0200 Subject: Major refactoring of RoundControl and TurnControl git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@516 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/control/turn/TurnControlTest.java | 100 ++++++++++++++++++++--- 1 file changed, 88 insertions(+), 12 deletions(-) (limited to 'test/jrummikub/control/turn') 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() { - @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { - eventFired = true; - } - }); + testControl.getEndOfTurnEvent().add( + new IListener3() { + @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() { - @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { - eventFired = true; - } - }); + testControl.getEndOfTurnEvent().add( + new IListener3() { + @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 expectedStones = new HashSet(); + expectedStones.add(blueThree); + expectedStones.add(blueFour); + + Set 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 newSets = AbstractTurnControl.tableSetDifference(oldTable, + newTable); + List 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()); + } + } -- cgit v1.2.3