summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/RoundControlTest.java
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/RoundControlTest.java
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/RoundControlTest.java')
-rw-r--r--test/jrummikub/control/RoundControlTest.java204
1 files changed, 56 insertions, 148 deletions
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<Score>() {
@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,11 +630,15 @@ 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();
@@ -664,80 +647,6 @@ public class RoundControlTest {
/** */
@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 = 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<StoneSet> newSets = RoundControl
- .tableSetDifference(oldTable, newTable);
- List<StoneSet> 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() {
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
@@ -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++) {