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/GameControlTest.java | 6 +- test/jrummikub/control/RoundControlTest.java | 204 +++++++---------------- test/jrummikub/control/turn/TurnControlTest.java | 100 +++++++++-- 3 files changed, 147 insertions(+), 163 deletions(-) (limited to 'test') diff --git a/test/jrummikub/control/GameControlTest.java b/test/jrummikub/control/GameControlTest.java index e1af261..7555714 100644 --- a/test/jrummikub/control/GameControlTest.java +++ b/test/jrummikub/control/GameControlTest.java @@ -49,10 +49,8 @@ public class GameControlTest { public void testEndOfRound() { gameControl.startGame(); - view.startTurnEvent.emit(); - // Manipulate first player's hand, to allow player1 to win - IHand playerHand = gameControl.roundControl.clonedHand; + IHand playerHand = gameControl.roundControl.roundState.getActivePlayer().getHand(); for (Pair entry : playerHand.clone()) { playerHand.pickUp(entry.getFirst()); } @@ -64,6 +62,8 @@ public class GameControlTest { playerHand.drop(stone3, new Position(0, 0)); // Done setting up first players hand + view.startTurnEvent.emit(); + view.playerPanel.endTurnEvent.emit(); view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java index edcb57f..8785fba 100644 --- a/test/jrummikub/control/RoundControlTest.java +++ b/test/jrummikub/control/RoundControlTest.java @@ -4,11 +4,7 @@ import static jrummikub.model.StoneColor.*; import static org.junit.Assert.*; import java.awt.Color; -import java.util.Arrays; -import java.util.HashSet; import java.util.Iterator; -import java.util.List; -import java.util.Set; import jrummikub.control.turn.TurnMode; import jrummikub.model.GameSettings; @@ -16,7 +12,6 @@ import jrummikub.model.Hand; import jrummikub.model.IHand; import jrummikub.model.IPlayer; import jrummikub.model.IRoundState; -import jrummikub.model.ITable; import jrummikub.model.MockRoundState; import jrummikub.model.MockTable; import jrummikub.model.PlayerSettings; @@ -25,7 +20,6 @@ import jrummikub.model.RoundState; import jrummikub.model.Score; import jrummikub.model.Stone; import jrummikub.model.StoneSet; -import jrummikub.model.Table; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.Pair; @@ -172,12 +166,12 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueOne, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0)); + view.startTurnEvent.emit(); assertFalse(roundState.getActivePlayer().getLaidOut()); @@ -191,7 +185,7 @@ public class RoundControlTest { assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) .getLaidOut()); assertEquals(0, roundState.getTable().getSize()); - assertEquals(14 + 6, hand.getSize()); + assertEquals(14 + 6, roundState.getActivePlayer().getHand().getSize()); } /** */ @@ -202,17 +196,16 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); - IHand hand = roundControl.clonedHand; + view.startTurnEvent.emit(); assertFalse(roundState.getActivePlayer().getLaidOut()); view.playerPanel.endTurnEvent.emit(); - assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(0, roundState.getTable().getSize()); - assertEquals(14 + 1, hand.getSize()); + + assertEquals(14 + 1, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** Threshold=30 */ @@ -223,12 +216,15 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueOne, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0)); + hand.drop(blueTen, new Position(0, 0)); + hand.drop(redTen, new Position(0, 0)); + hand.drop(blueEleven, new Position(0, 0)); + view.startTurnEvent.emit(); view.handPanel.stoneClickEvent.emit(blueOne, false); view.handPanel.stoneClickEvent.emit(blueTwo, true); @@ -238,10 +234,6 @@ public class RoundControlTest { assertFalse(roundState.getActivePlayer().getLaidOut()); - hand.drop(blueTen, new Position(0, 0)); - hand.drop(redTen, new Position(0, 0)); - hand.drop(blueEleven, new Position(0, 0)); - view.handPanel.stoneClickEvent.emit(blueTen, false); view.handPanel.stoneClickEvent.emit(redTen, true); view.handPanel.stoneClickEvent.emit(blueEleven, true); @@ -249,10 +241,12 @@ public class RoundControlTest { view.tablePanel.clickEvent.emit(new Position(0, 0)); view.playerPanel.endTurnEvent.emit(); - assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + view.acknowledgeInvalidEvent.emit(); + + assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(0, roundState.getTable().getSize()); - assertEquals(14 + 9, hand.getSize()); + + assertEquals(14 + 9, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** Threshold=30 */ @@ -263,9 +257,8 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); // Fake Turn to put stones on the table - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueOne, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0)); @@ -274,6 +267,7 @@ public class RoundControlTest { hand.drop(blueSeven, new Position(0, 0)); hand.drop(blackSeven, new Position(0, 0)); hand.drop(orangeSeven, new Position(0, 0)); + view.startTurnEvent.emit(); view.handPanel.stoneClickEvent.emit(redSeven, false); view.handPanel.stoneClickEvent.emit(blueSeven, true); @@ -290,12 +284,12 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); assertEquals(2, roundState.getTable().getSize()); - view.startTurnEvent.emit(); - hand = roundControl.clonedHand; + hand = roundState.getActivePlayer().getHand(); hand.drop(redEight, new Position(0, 0)); hand.drop(redNine, new Position(0, 0)); hand.drop(redTen, new Position(0, 0)); + view.startTurnEvent.emit(); view.tablePanel.stoneClickEvent.emit(redSeven, false); view.handPanel.stoneClickEvent.emit(redEight, true); @@ -308,10 +302,9 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); view.acknowledgeInvalidEvent.emit(); - assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(2, roundState.getTable().getSize()); - assertEquals(14 + 6, hand.getSize()); + assertEquals(14 + 6, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** Threshold=30 */ @@ -322,9 +315,8 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); // Fake Turn to put stones on the table - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueOne, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0)); @@ -333,6 +325,7 @@ public class RoundControlTest { hand.drop(blueSeven, new Position(0, 0)); hand.drop(blackSeven, new Position(0, 0)); hand.drop(orangeSeven, new Position(0, 0)); + view.startTurnEvent.emit(); view.handPanel.stoneClickEvent.emit(redSeven, false); view.handPanel.stoneClickEvent.emit(blueSeven, true); @@ -349,13 +342,13 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); assertEquals(2, roundState.getTable().getSize()); - view.startTurnEvent.emit(); - hand = roundControl.clonedHand; + hand = roundState.getActivePlayer().getHand(); hand.drop(redEight, new Position(0, 0)); hand.drop(redNine, new Position(0, 0)); hand.drop(redTen, new Position(0, 0)); hand.drop(redEleven, new Position(0, 0)); + view.startTurnEvent.emit(); view.tablePanel.stoneClickEvent.emit(redSeven, false); view.handPanel.stoneClickEvent.emit(redEight, true); @@ -369,10 +362,9 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); view.acknowledgeInvalidEvent.emit(); - assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(2, roundState.getTable().getSize()); - assertEquals(14 + 7, hand.getSize()); + assertEquals(14 + 7, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** */ @@ -383,9 +375,8 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); // Fake Turn to put stones on the table - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueFive, new Position(0, 0)); hand.drop(blueSix, new Position(0, 0)); hand.drop(blueSeven, new Position(0, 0)); @@ -394,6 +385,7 @@ public class RoundControlTest { hand.drop(blueFour, new Position(0, 0)); hand.drop(blackFour, new Position(0, 0)); hand.drop(orangeFour, new Position(0, 0)); + view.startTurnEvent.emit(); view.handPanel.stoneClickEvent.emit(redFour, false); view.handPanel.stoneClickEvent.emit(blueFour, true); @@ -410,10 +402,8 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); assertEquals(2, roundState.getTable().getSize()); - view.startTurnEvent.emit(); - - hand = roundControl.clonedHand; + view.startTurnEvent.emit(); view.tablePanel.stoneClickEvent.emit(blueFour, false); view.tablePanel.stoneClickEvent.emit(blueFive, true); view.tablePanel.stoneClickEvent.emit(blueSix, true); @@ -425,10 +415,9 @@ public class RoundControlTest { view.playerPanel.endTurnEvent.emit(); view.acknowledgeInvalidEvent.emit(); - assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(2, roundState.getTable().getSize()); - assertEquals(14 + 3, hand.getSize()); + assertEquals(14 + 3, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** Threshold=30 */ @@ -439,9 +428,8 @@ public class RoundControlTest { view.startTurnEvent.emit(); view.playerPanel.endTurnEvent.emit(); } - view.startTurnEvent.emit(); // Fake Turn to put stones on the table - IHand hand = roundControl.clonedHand; + IHand hand = roundState.getActivePlayer().getHand(); hand.drop(blueOne, new Position(0, 0)); hand.drop(blueTwo, new Position(0, 0)); hand.drop(blueThree, new Position(0, 0)); @@ -450,6 +438,7 @@ public class RoundControlTest { hand.drop(blueSeven, new Position(0, 0)); hand.drop(blackSeven, new Position(0, 0)); hand.drop(orangeSeven, new Position(0, 0)); + view.startTurnEvent.emit(); view.handPanel.stoneClickEvent.emit(redSeven, false); view.handPanel.stoneClickEvent.emit(blueSeven, true); @@ -465,22 +454,9 @@ public class RoundControlTest { view.tablePanel.clickEvent.emit(new Position(0, 0)); view.playerPanel.endTurnEvent.emit(); - assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) - .getLaidOut()); + assertTrue(roundState.getNthNextPlayer(-1).getLaidOut()); assertEquals(2, roundState.getTable().getSize()); - assertEquals(14, hand.getSize()); - } - - /** */ - @Test - public void testDealStones() { - testRound.deal(); - checkCorrectlyDealt(); - for (int i = 0; i < 14; i++) { - testRound.dealStones(2); - } - assertEquals(2 * 14 + 14, testRoundState.getActivePlayer().getHand() - .getSize()); + assertEquals(14, roundState.getNthNextPlayer(-1).getHand().getSize()); } /** */ @@ -512,6 +488,7 @@ public class RoundControlTest { /** */ @Test public void testTableValidHandChanged() { + fail(); testRoundState.players.get(0).setLaidOut(true); testRound.startRound(); for (int i = 0; i < 4; i++) { @@ -539,6 +516,7 @@ public class RoundControlTest { /** */ @Test public void testTableInvalidHandChanged() { + fail(); testRound.startRound(); for (int i = 0; i < 4; i++) { view.startTurnEvent.emit(); @@ -548,9 +526,9 @@ public class RoundControlTest { testTable.valid = false; oldTable.clonedTable = testTable; + IHand hand = testRoundState.getActivePlayer().getHand(); view.startTurnEvent.emit(); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); - IHand hand = testRound.clonedHand; Stone stone = hand.iterator().next().getFirst(); hand.pickUp(stone); testTable.drop(new StoneSet(stone), new Position(0, 0)); @@ -567,6 +545,7 @@ public class RoundControlTest { /** */ @Test public void testTableValidHandUnchanged() { + fail(); testRoundState.players.get(0).setLaidOut(true); testRound.startRound(); for (int i = 0; i < 4; i++) { @@ -592,6 +571,7 @@ public class RoundControlTest { /** */ @Test public void testTableInvalidHandUnchanged() { + fail(); testRoundState.players.get(1).setLaidOut(true); testRound.startRound(); for (int i = 0; i < 4; i++) { @@ -618,7 +598,6 @@ public class RoundControlTest { /** */ @Test public void testWinning() { - testRound.getEndOfRoundEvent().add(new IListener1() { @Override public void handle(Score roundScore) { @@ -635,14 +614,14 @@ public class RoundControlTest { testTable.valid = true; oldTable.clonedTable = testTable; - view.startTurnEvent.emit(); - assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); - IHand hand = testRound.clonedHand; + IHand hand = testRoundState.getActivePlayer().getHand(); hand.drop(redEight, new Position(0, 0)); hand.drop(blueEight, new Position(0, 0)); hand.drop(blackEight, new Position(0, 0)); hand.drop(orangeEight, new Position(0, 0)); + view.startTurnEvent.emit(); + assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); view.handPanel.stoneClickEvent.emit(redEight, false); view.handPanel.stoneClickEvent.emit(blueEight, true); @@ -651,91 +630,21 @@ public class RoundControlTest { view.tablePanel.clickEvent.emit(new Position(0, 0)); - for (int i = 0; i < 4; i++) { - testRoundState.players.get(i).hand = new Hand(); + view.playerPanel.endTurnEvent.emit(); + + for (int i = 0; i < 3; i++) { + view.startTurnEvent.emit(); + view.playerPanel.endTurnEvent.emit(); } - testRound.clonedHand = (IHand) testRoundState.players.get(3).hand.clone(); - resetTurnStart(); + + testRoundState.getActivePlayer().setHand(new Hand()); + view.startTurnEvent.emit(); assertFalse(roundEnded); view.playerPanel.endTurnEvent.emit(); assertTrue(roundEnded); } - /** */ - @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 = RoundControl.tableDifference(oldTable, newTable); - - assertTrue(expectedStones.containsAll(stones)); - assertTrue(stones.containsAll(expectedStones)); - } - - /** */ - @Test - public void testTableSetDifference() { - ITable oldTable = new Table(gameSettings); - 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 = RoundControl - .tableSetDifference(oldTable, newTable); - List vanishedSets = RoundControl.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 = RoundControl.tableSetDifference(oldTable, newTable); - vanishedSets = RoundControl.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 = RoundControl.tableSetDifference(oldTable, newTable2); - vanishedSets = RoundControl.tableSetDifference(newTable2, oldTable); - - assertFalse(newSets.isEmpty()); - assertTrue(vanishedSets.isEmpty()); - assertEquals(1, newSets.size()); - } - /** */ @Test public void heapIsEmpty() { @@ -899,12 +808,12 @@ public class RoundControlTest { @Test public void testRedealDisallowed() { testRound.startRound(); - view.startTurnEvent.emit(); Hand hand = new Hand(); hand.drop(new Stone(1, RED), new Position(0, 0)); hand.drop(new Stone(1, BLACK), new Position(0, 0)); hand.drop(new Stone(1, BLUE), new Position(0, 0)); - testRound.clonedHand = hand; + testRoundState.players.get(0).hand = hand; + view.startTurnEvent.emit(); assertEquals(TurnMode.INSPECT_ONLY, view.playerPanel.turnMode); for (int i = 0; i < 4; i++) { view.playerPanel.endTurnEvent.emit(); @@ -922,7 +831,6 @@ public class RoundControlTest { hand.drop(new Stone(i / 2 + 1, RED), new Position(0, 0)); } testRoundState.players.get(0).hand = hand; - testRound.clonedHand = (IHand) hand.clone(); view.startTurnEvent.emit(); assertEquals(TurnMode.MAY_REDEAL, view.playerPanel.turnMode); for (int i = 0; i < 4; i++) { 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