Tests für RoundControl gefixt

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@524 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-21 01:46:36 +02:00
parent f304f20cbc
commit 72912be600
3 changed files with 202 additions and 135 deletions

View file

@ -4,6 +4,7 @@ import static jrummikub.model.StoneColor.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.awt.Color; import java.awt.Color;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import jrummikub.control.turn.TurnMode; import jrummikub.control.turn.TurnMode;
@ -97,21 +98,24 @@ public class RoundControlTest {
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add( gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW)); new PlayerSettings("Matthias", Color.YELLOW));
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN)); gameSettings.getPlayerList().add(
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK)); new PlayerSettings("Jannis", Color.GREEN));
gameSettings.getPlayerList().add(
new PlayerSettings("Bennet", Color.BLACK));
roundState = new RoundState(gameSettings, null); roundState = new RoundState(gameSettings, null);
roundControl = new RoundControl(roundState, view); roundControl = new RoundControl(roundState, view);
} }
private void checkCorrectlyDealt() { private void checkCorrectlyDealt() {
GameSettings settings = testRoundState.getGameSettings(); GameSettings settings = testRoundState.getGameSettings();
int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() int totalStones = settings.getHighestValue()
* settings.getStoneSetNumber()
* settings.getStoneColors().size() + settings.getJokerNumber(); * settings.getStoneColors().size() + settings.getJokerNumber();
assertEquals( assertEquals(
totalStones - testRoundState.getPlayerCount() totalStones - testRoundState.getPlayerCount()
* settings.getNumberOfStonesDealt() * settings.getNumberOfStonesDealt()
- testRoundState.table.getSize(), testRoundState.getGameHeap() - testRoundState.table.getSize(), testRoundState
.getSize()); .getGameHeap().getSize());
for (int i = 0; i < testRoundState.getPlayerCount(); i++) { for (int i = 0; i < testRoundState.getPlayerCount(); i++) {
assertEquals(settings.getNumberOfStonesDealt(), testRoundState assertEquals(settings.getNumberOfStonesDealt(), testRoundState
.getNthNextPlayer(i).getHand().getSize()); .getNthNextPlayer(i).getHand().getSize());
@ -182,8 +186,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 6, roundState.getActivePlayer().getHand().getSize()); assertEquals(14 + 6, roundState.getActivePlayer().getHand().getSize());
} }
@ -205,7 +209,8 @@ public class RoundControlTest {
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 1, roundState.getNthNextPlayer(-1).getHand().getSize()); assertEquals(14 + 1, roundState.getNthNextPlayer(-1).getHand()
.getSize());
} }
/** Threshold=30 */ /** Threshold=30 */
@ -246,7 +251,8 @@ public class RoundControlTest {
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 9, roundState.getNthNextPlayer(-1).getHand().getSize()); assertEquals(14 + 9, roundState.getNthNextPlayer(-1).getHand()
.getSize());
} }
/** Threshold=30 */ /** Threshold=30 */
@ -304,7 +310,8 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit(); view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 6, roundState.getNthNextPlayer(-1).getHand().getSize()); assertEquals(14 + 6, roundState.getNthNextPlayer(-1).getHand()
.getSize());
} }
/** Threshold=30 */ /** Threshold=30 */
@ -364,7 +371,8 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit(); view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 7, roundState.getNthNextPlayer(-1).getHand().getSize()); assertEquals(14 + 7, roundState.getNthNextPlayer(-1).getHand()
.getSize());
} }
/** */ /** */
@ -417,7 +425,8 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit(); view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut()); assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 3, roundState.getNthNextPlayer(-1).getHand().getSize()); assertEquals(14 + 3, roundState.getNthNextPlayer(-1).getHand()
.getSize());
} }
/** Threshold=30 */ /** Threshold=30 */
@ -487,8 +496,7 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void testTableValidHandChanged() { public void testTableValidTableChanged() {
fail();
testRoundState.players.get(0).setLaidOut(true); testRoundState.players.get(0).setLaidOut(true);
testRound.startRound(); testRound.startRound();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -496,18 +504,23 @@ public class RoundControlTest {
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
} }
MockTable oldTable = testRoundState.table; MockTable oldTable = testRoundState.table;
oldTable.sets.clear();
testTable.valid = true; testTable.valid = true;
testTable.sets.clear();
testTable.drop(
new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
orangeEight)), new Position(0, 0));
oldTable.clonedTable = testTable; oldTable.clonedTable = testTable;
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
IHand hand = testRoundState.players.get(0).hand;
hand.pickUp(hand.iterator().next().getFirst());
resetTurnStart(); resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit(); view.getPlayerPanel().endTurnEvent.emit();
assertSame(testTable, testRoundState.setTable); assertSame(testTable, testRoundState.setTable);
assertEquals(14, testRoundState.players.get(0).getHand().getSize());
assertEquals(1, testRoundState.activePlayer); assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp(); checkTurnStartSetUp();
@ -515,37 +528,38 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void testTableInvalidHandChanged() { public void testTableInvalidTableChanged() {
fail();
testRound.startRound(); testRound.startRound();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
view.startTurnEvent.emit(); view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
} }
MockTable oldTable = testRoundState.table; MockTable oldTable = testRoundState.table;
oldTable.sets.clear();
testTable.valid = false; testTable.valid = false;
testTable.sets.clear();
testTable.drop(
new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
blackFour)), new Position(0, 0));
oldTable.clonedTable = testTable; oldTable.clonedTable = testTable;
IHand hand = testRoundState.getActivePlayer().getHand();
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone);
testTable.drop(new StoneSet(stone), new Position(0, 0));
resetTurnStart(); resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit(); view.getPlayerPanel().endTurnEvent.emit();
view.acknowledgeInvalidEvent.emit(); view.acknowledgeInvalidEvent.emit();
assertNull(testRoundState.setTable); assertNull(testRoundState.setTable);
assertEquals(1, testRoundState.activePlayer); assertEquals(1, testRoundState.activePlayer);
assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize()); assertEquals(14 + 4 + 3, testRoundState.players.get(0).hand.getSize());
checkTurnStartSetUp(); checkTurnStartSetUp();
} }
/** */ /** */
@Test @Test
public void testTableValidHandUnchanged() { public void testTableValidTabelUnchanged() {
fail();
testRoundState.players.get(0).setLaidOut(true); testRoundState.players.get(0).setLaidOut(true);
testRound.startRound(); testRound.startRound();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -553,7 +567,10 @@ public class RoundControlTest {
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
} }
MockTable oldTable = testRoundState.table; MockTable oldTable = testRoundState.table;
oldTable.sets.clear();
testTable.valid = true; testTable.valid = true;
testTable.sets.clear();
oldTable.clonedTable = testTable; oldTable.clonedTable = testTable;
view.startTurnEvent.emit(); view.startTurnEvent.emit();
@ -570,8 +587,7 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void testTableInvalidHandUnchanged() { public void testTableInvalidTabelReordered() {
fail();
testRoundState.players.get(1).setLaidOut(true); testRoundState.players.get(1).setLaidOut(true);
testRound.startRound(); testRound.startRound();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -579,11 +595,22 @@ public class RoundControlTest {
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
} }
MockTable oldTable = testRoundState.table; MockTable oldTable = testRoundState.table;
testTable.valid = false; oldTable.sets.clear();
oldTable.clonedTable = testTable; oldTable.drop(
new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
orangeEight)), new Position(0, 0));
testTable.valid = false;
testTable.sets.clear();
oldTable.clonedTable = testTable;
testTable.drop(new StoneSet(Arrays.asList(blueEight, blackEight)),
new Position(0, 0));
testTable.drop(new StoneSet(Arrays.asList(redEight, orangeEight)),
new Position(0, 0));
view.startTurnEvent.emit(); view.startTurnEvent.emit();
assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType); assertSame(BottomPanelType.HUMAN_HAND_PANEL, view.bottomPanelType);
resetTurnStart(); resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit(); view.getPlayerPanel().endTurnEvent.emit();
view.acknowledgeInvalidEvent.emit(); view.acknowledgeInvalidEvent.emit();
@ -696,19 +723,20 @@ public class RoundControlTest {
} }
testRoundState.players.get(0).laidOut = true; testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(1, RED),
0)); new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(2, RED),
0)); new Position(0, 0));
testRoundState.players.get(1).laidOut = true; testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0, 0)); testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0,
0));
testRoundState.players.get(2).laidOut = false; testRoundState.players.get(2).laidOut = false;
testRoundState.players.get(2).hand.drop(new Stone(9, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(9, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(10, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(10, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(11, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(11, RED),
0)); new Position(0, 0));
testRoundState.players.get(3).laidOut = true; testRoundState.players.get(3).laidOut = true;
testRound.endOfRound(); testRound.endOfRound();
@ -742,19 +770,19 @@ public class RoundControlTest {
} }
testRoundState.players.get(0).laidOut = true; testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(1, RED),
0)); new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(2, RED),
0)); new Position(0, 0));
testRoundState.players.get(1).laidOut = true; testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(3, RED), new Position(0, testRoundState.players.get(1).hand.drop(new Stone(3, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).laidOut = true; testRoundState.players.get(2).laidOut = true;
testRoundState.players.get(2).hand.drop(new Stone(3, BLUE), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(3, BLUE),
0)); new Position(0, 0));
testRoundState.players.get(3).laidOut = false; testRoundState.players.get(3).laidOut = false;
testRoundState.players.get(3).hand.drop(new Stone(13, RED), new Position(0, testRoundState.players.get(3).hand.drop(new Stone(13, RED),
0)); new Position(0, 0));
testRound.endOfRound(); testRound.endOfRound();
assertTrue(roundEnded); assertTrue(roundEnded);

View file

@ -35,8 +35,10 @@ public class NetworkRoundControlTest {
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED)); gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add( gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW)); new PlayerSettings("Matthias", Color.YELLOW));
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN)); gameSettings.getPlayerList().add(
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK)); new PlayerSettings("Jannis", Color.GREEN));
gameSettings.getPlayerList().add(
new PlayerSettings("Bennet", Color.BLACK));
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER); gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
gameSettings.getPlayerList().get(2).setType(Type.NETWORK); gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
@ -48,7 +50,8 @@ public class NetworkRoundControlTest {
@Test @Test
public void testHostRound() { public void testHostRound() {
connectionControl.nickname = gameSettings.getPlayerList().get(0).getName(); connectionControl.nickname = gameSettings.getPlayerList().get(0)
.getName();
testRoundState = new RoundState(gameSettings, null); testRoundState = new RoundState(gameSettings, null);
testRound = new NetworkRoundControl(testRoundState, view, testRound = new NetworkRoundControl(testRoundState, view,
@ -64,8 +67,8 @@ public class NetworkRoundControlTest {
IPlayer player = testRoundState.getNthPlayer(i); IPlayer player = testRoundState.getNthPlayer(i);
assertSame(gameSettings.getPlayerList().get(i), assertSame(gameSettings.getPlayerList().get(i),
player.getPlayerSettings()); player.getPlayerSettings());
assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand() assertEquals(gameSettings.getNumberOfStonesDealt(), player
.getSize()); .getHand().getSize());
} }
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
@ -77,45 +80,50 @@ public class NetworkRoundControlTest {
} }
} }
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(0),
testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted); assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.turnEnded);
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertTrue(connectionControl.turnEnded); assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false; connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(1),
testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted); assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit();
assertTrue(connectionControl.turnEnded); assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false; connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(2),
testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted); assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() connectionControl.turnEndEvent.emit(testRoundState);
.getHand(), testRoundState.getTable(), testRoundState.getTable());
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(3),
testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted); assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable()); .getHand(), testRoundState.getTable(), testRoundState
.getTable());
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(0),
testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted); assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit(testRoundState);
@ -124,41 +132,49 @@ public class NetworkRoundControlTest {
@Test @Test
public void testClientRound() { public void testClientRound() {
connectionControl.nickname = gameSettings.getPlayerList().get(2).getName(); connectionControl.nickname = gameSettings.getPlayerList().get(2)
.getName();
testRoundState = new RoundState(gameSettings, null); testRoundState = new RoundState(gameSettings, null);
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
IPlayer player = testRoundState.getNthPlayer(i); IPlayer player = testRoundState.getNthPlayer(i);
player.getHand().drop(new Stone(StoneColor.RED), new Position(0, 0)); player.getHand()
.drop(new Stone(StoneColor.RED), new Position(0, 0));
} }
testRound = new NetworkRoundControl(null, view, connectionControl, false); testRound = new NetworkRoundControl(null, view, connectionControl,
false);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;
connectionControl.turnEnded = false; connectionControl.turnEnded = false;
testRound.startRound(); testRound.startRound();
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(0),
testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted); assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable()); .getHand(), testRoundState.getTable(), testRoundState
.getTable());
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(1),
testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted); assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit(testRoundState);
assertFalse(connectionControl.turnEnded); assertFalse(connectionControl.turnEnded);
connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer() connectionControl.turnEndEvent.emit(testRoundState.getActivePlayer()
.getHand(), testRoundState.getTable(), testRoundState.getTable()); .getHand(), testRoundState.getTable(), testRoundState
.getTable());
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(2),
testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted); assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit(testRoundState); connectionControl.turnStartEvent.emit(testRoundState);
@ -168,7 +184,8 @@ public class NetworkRoundControlTest {
assertTrue(connectionControl.turnEnded); assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false; connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(3),
testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted); assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;
@ -176,7 +193,8 @@ public class NetworkRoundControlTest {
assertTrue(connectionControl.turnEnded); assertTrue(connectionControl.turnEnded);
connectionControl.turnEnded = false; connectionControl.turnEnded = false;
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer()); assertSame(testRoundState.getNthPlayer(0),
testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted); assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false; connectionControl.turnStarted = false;

View file

@ -1,7 +1,13 @@
package jrummikub.control.turn; package jrummikub.control.turn;
import static jrummikub.model.StoneColor.*; import static jrummikub.model.StoneColor.BLACK;
import static org.junit.Assert.*; import static jrummikub.model.StoneColor.BLUE;
import static jrummikub.model.StoneColor.ORANGE;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -12,11 +18,16 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import jrummikub.control.ITurnTimer; import jrummikub.control.ITurnTimer;
import jrummikub.control.RoundControl;
import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.control.turn.ITurnControl.TurnInfo;
import jrummikub.model.GameSettings; import jrummikub.model.GameSettings;
import jrummikub.model.IHand; import jrummikub.model.IHand;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable; import jrummikub.model.ITable;
import jrummikub.model.MockHand; import jrummikub.model.MockHand;
import jrummikub.model.MockPlayer; import jrummikub.model.MockPlayer;
import jrummikub.model.MockRoundState;
import jrummikub.model.MockTable; import jrummikub.model.MockTable;
import jrummikub.model.Position; import jrummikub.model.Position;
import jrummikub.model.Stone; import jrummikub.model.Stone;
@ -25,6 +36,7 @@ import jrummikub.model.StoneSet;
import jrummikub.model.Table; import jrummikub.model.Table;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.IListener2;
import jrummikub.util.IListener3; import jrummikub.util.IListener3;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType; import jrummikub.view.IView.BottomPanelType;
@ -75,6 +87,7 @@ public class TurnControlTest {
MockTimer mockTimer; MockTimer mockTimer;
MockTable mockTable; MockTable mockTable;
MockHand mockHand; MockHand mockHand;
private MockRoundState mockRoundState;
boolean eventFired; boolean eventFired;
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); Stone redOne = new Stone(1, RED);
@ -127,15 +140,15 @@ public class TurnControlTest {
@Before @Before
public void setUp() { public void setUp() {
mockView = new MockView(); mockView = new MockView();
mockRoundState = new MockRoundState();
mockTimer = new MockTimer(); mockTimer = new MockTimer();
mockTable = new MockTable(); mockTable = new MockTable();
mockHand = new MockHand(); mockHand = new MockHand();
mockPlayer = new MockPlayer(null, null); mockPlayer = new MockPlayer(null, null);
mockPlayer.hand = mockHand; mockPlayer.hand = mockHand;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new ITurnControl.TurnInfo(mockTable, testControl.setup(new ITurnControl.TurnInfo(mockRoundState,
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
new GameSettings(), mockView);
} }
/** */ /** */
@ -159,9 +172,8 @@ public class TurnControlTest {
mockHand.iterable = stones; mockHand.iterable = stones;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new ITurnControl.TurnInfo(mockTable, testControl.setup(new ITurnControl.TurnInfo(mockRoundState,
mockPlayer.getHand(), mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
new GameSettings(), mockView);
testControl.startTurn(); testControl.startTurn();
int i = 0; int i = 0;
@ -183,9 +195,10 @@ public class TurnControlTest {
mockTimer.timerRunning = true; mockTimer.timerRunning = true;
testControl.getEndOfTurnEvent().add( testControl.getEndOfTurnEvent().add(
new IListener3<IHand, ITable, ITable>() { new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() {
@Override @Override
public void handle(IHand oldHand, ITable oldTable, ITable newTable) { public void handle(IRoundState roundState,
RoundControl.InvalidTurnInfo invalidTurnInfo) {
eventFired = true; eventFired = true;
} }
}); });
@ -206,9 +219,10 @@ public class TurnControlTest {
mockTimer.timerRunning = true; mockTimer.timerRunning = true;
testControl.getEndOfTurnEvent().add( testControl.getEndOfTurnEvent().add(
new IListener3<IHand, ITable, ITable>() { new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() {
@Override @Override
public void handle(IHand oldHand, ITable oldTable, ITable newTable) { public void handle(IRoundState value1,
InvalidTurnInfo value2) {
eventFired = true; eventFired = true;
} }
}); });
@ -292,8 +306,8 @@ public class TurnControlTest {
mockView.handPanel.stoneClickEvent.emit(redJoker, true); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
mockView.handPanel.stoneClickEvent.emit(blackJoker, true); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(blackJoker, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
true); blackJoker, true);
assertCollection(Arrays.asList(redJoker, blackJoker)); assertCollection(Arrays.asList(redJoker, blackJoker));
} }
@ -309,7 +323,8 @@ public class TurnControlTest {
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
true); true);
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, true); mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker,
true);
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
} }
@ -407,8 +422,8 @@ public class TurnControlTest {
testControl.startTurn(); testControl.startTurn();
Stone stone4 = new Stone(4, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED);
StoneSet set1 = new StoneSet( StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree,
Arrays.asList(redOne, redTwo, redThree, stone4)); stone4));
mockTable.findStoneSet.put(redOne, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(redThree, set1); mockTable.findStoneSet.put(redThree, set1);
@ -575,15 +590,14 @@ public class TurnControlTest {
public void testAddLeft() { public void testAddLeft() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new ITurnControl.TurnInfo(mockRoundState,
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), TurnMode.NORMAL_TURN), new GameSettings(), mockView);
mockView);
turnControl.startTurn(); turnControl.startTurn();
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -682,14 +696,13 @@ public class TurnControlTest {
public void testAddRight() { public void testAddRight() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN),
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), new GameSettings(), mockView);
mockView);
turnControl.startTurn(); turnControl.startTurn();
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -788,14 +801,13 @@ public class TurnControlTest {
public void testAddNewSet() { public void testAddNewSet() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new ITurnControl.TurnInfo(table, mockPlayer.getHand(), turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN),
mockPlayer.getLaidOut(), TurnMode.NORMAL_TURN), new GameSettings(), new GameSettings(), mockView);
mockView);
turnControl.startTurn(); turnControl.startTurn();
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
redTwo, redThree, redFour, blackTwo, blackThree)); blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet( StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
Arrays.asList(blueTwo, blackFour, blackFive)); blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
@ -886,8 +898,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections Collections.sort(stones,
.sort(stones, new HumanTurnControl.HandStonePositionComparator()); new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
@ -935,8 +947,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections Collections.sort(stones,
.sort(stones, new HumanTurnControl.HandStonePositionComparator()); new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
@ -976,8 +988,8 @@ public class TurnControlTest {
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
Set<Stone> expected = new HashSet<Stone>( Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
Arrays.asList(redJoker, blackJoker)); blackJoker));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1004,7 +1016,8 @@ public class TurnControlTest {
assertCollection(Arrays.asList(blackJoker)); assertCollection(Arrays.asList(blackJoker));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker, black13)); Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker,
black13));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1020,12 +1033,15 @@ public class TurnControlTest {
public void testTableDifference() { public void testTableDifference() {
MockTable oldTable = new MockTable(); MockTable oldTable = new MockTable();
MockTable newTable = new MockTable(); MockTable newTable = new MockTable();
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne)); StoneSet oldSet1 = new StoneSet(
Arrays.asList(blueOne, redOne, blackOne));
StoneSet oldSet2 = new StoneSet(blueTwo); StoneSet oldSet2 = new StoneSet(blueTwo);
oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0));
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour)); StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo,
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree)); blueFour));
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne,
blueThree));
newTable.drop(newSet1, new Position(0, 0)); newTable.drop(newSet1, new Position(0, 0));
newTable.drop(newSet2, new Position(0, 0)); newTable.drop(newSet2, new Position(0, 0));
@ -1033,7 +1049,8 @@ public class TurnControlTest {
expectedStones.add(blueThree); expectedStones.add(blueThree);
expectedStones.add(blueFour); expectedStones.add(blueFour);
Set<Stone> stones = AbstractTurnControl.tableDifference(oldTable, newTable); Set<Stone> stones = AbstractTurnControl.tableDifference(oldTable,
newTable);
assertTrue(expectedStones.containsAll(stones)); assertTrue(expectedStones.containsAll(stones));
assertTrue(stones.containsAll(expectedStones)); assertTrue(stones.containsAll(expectedStones));
@ -1050,14 +1067,15 @@ public class TurnControlTest {
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE); Stone blueFour = new Stone(4, BLUE);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
orangeOne)); blackOne, orangeOne));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour)); StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree,
blueFour));
oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0));
ITable newTable = (Table) oldTable.clone(); ITable newTable = (Table) oldTable.clone();
List<StoneSet> newSets = AbstractTurnControl.tableSetDifference(oldTable, List<StoneSet> newSets = AbstractTurnControl.tableSetDifference(
newTable); oldTable, newTable);
List<StoneSet> vanishedSets = AbstractTurnControl.tableSetDifference( List<StoneSet> vanishedSets = AbstractTurnControl.tableSetDifference(
newTable, oldTable); newTable, oldTable);
@ -1065,10 +1083,11 @@ public class TurnControlTest {
assertTrue(vanishedSets.isEmpty()); assertTrue(vanishedSets.isEmpty());
newTable.pickUp(oldSet2); newTable.pickUp(oldSet2);
newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position( newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))),
0, 0)); new Position(0, 0));
newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable);
vanishedSets = AbstractTurnControl.tableSetDifference(newTable, oldTable); vanishedSets = AbstractTurnControl.tableSetDifference(newTable,
oldTable);
assertFalse(newSets.isEmpty()); assertFalse(newSets.isEmpty());
assertFalse(vanishedSets.isEmpty()); assertFalse(vanishedSets.isEmpty());
@ -1078,11 +1097,13 @@ public class TurnControlTest {
Stone redTwo = new Stone(2, RED); Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED); Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED); Stone redFour = new Stone(4, RED);
StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour)); StoneSet oldSet3 = new StoneSet(
Arrays.asList(redTwo, redThree, redFour));
ITable newTable2 = (Table) oldTable.clone(); ITable newTable2 = (Table) oldTable.clone();
newTable2.drop(oldSet3, new Position(0, 0)); newTable2.drop(oldSet3, new Position(0, 0));
newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2);
vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, oldTable); vanishedSets = AbstractTurnControl.tableSetDifference(newTable2,
oldTable);
assertFalse(newSets.isEmpty()); assertFalse(newSets.isEmpty());
assertTrue(vanishedSets.isEmpty()); assertTrue(vanishedSets.isEmpty());