diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-22 10:38:10 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-06-22 10:38:10 +0200 |
commit | f5aa073827980bdae3e530b6ea9d8c17807ad764 (patch) | |
tree | 8d64a1816516a152b03868c14bee551474690c28 /test | |
parent | e1df2b8e8866280f62159a5bc70d9aca390ca9bf (diff) | |
download | JRummikub-f5aa073827980bdae3e530b6ea9d8c17807ad764.tar JRummikub-f5aa073827980bdae3e530b6ea9d8c17807ad764.zip |
Some missing control tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@591 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r-- | test/jrummikub/control/GameControlTest.java | 80 | ||||
-rw-r--r-- | test/jrummikub/control/turn/AIControlTest.java | 24 |
2 files changed, 103 insertions, 1 deletions
diff --git a/test/jrummikub/control/GameControlTest.java b/test/jrummikub/control/GameControlTest.java index a9273ef..68dda26 100644 --- a/test/jrummikub/control/GameControlTest.java +++ b/test/jrummikub/control/GameControlTest.java @@ -10,6 +10,7 @@ import jrummikub.model.IHand; import jrummikub.model.PlayerSettings; import jrummikub.model.Position; import jrummikub.model.Stone; +import jrummikub.util.IListener; import jrummikub.util.Pair; import jrummikub.view.IView.BottomPanelType; import jrummikub.view.MockView; @@ -24,6 +25,7 @@ public class GameControlTest { private GameControl gameControl; private GameSettings gameSettings; private MockView view; + protected boolean gameEnded; /** */ @Before @@ -81,6 +83,84 @@ public class GameControlTest { view.newRoundEvent.emit(); assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType); } + + @Test + public void testNewGame() { + gameControl.getEndOfGameEvent().add(new IListener() { + @Override + public void handle() { + gameEnded = true; + } + }); + + gameEnded = false; + + gameControl.startGame(); + // Manipulate first player's hand, to allow player1 to win + IHand playerHand = gameControl.roundControl.roundState.getActivePlayer().getHand(); + for (Pair<Stone, Position> entry : playerHand.clone()) { + playerHand.pickUp(entry.getFirst()); + } + Stone stone1 = new Stone(9, RED); + Stone stone2 = new Stone(10, RED); + Stone stone3 = new Stone(11, RED); + playerHand.drop(stone1, new Position(0, 0)); + playerHand.drop(stone2, new Position(0, 0)); + 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(); + view.startTurnEvent.emit(); + + view.handPanel.stoneClickEvent.emit(stone1, false); + view.handPanel.stoneClickEvent.emit(stone2, true); + view.handPanel.stoneClickEvent.emit(stone3, true); + + view.tablePanel.clickEvent.emit(new Position(0, 0)); + view.playerPanel.endTurnEvent.emit(); + + assertSame(BottomPanelType.WIN_PANEL, view.bottomPanelType); + + + assertFalse(gameEnded); + view.newGameEvent.emit(); + assertTrue(gameEnded); + } + + @Test + public void testAborting() { + gameControl.startGame(); + + // Manipulate first player's hand, to allow player1 to win + IHand playerHand = gameControl.roundControl.roundState.getActivePlayer().getHand(); + for (Pair<Stone, Position> entry : playerHand.clone()) { + playerHand.pickUp(entry.getFirst()); + } + Stone stone1 = new Stone(9, RED); + Stone stone2 = new Stone(10, RED); + Stone stone3 = new Stone(11, RED); + playerHand.drop(stone1, new Position(0, 0)); + playerHand.drop(stone2, new Position(0, 0)); + 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(); + view.startTurnEvent.emit(); + + view.handPanel.stoneClickEvent.emit(stone1, false); + view.handPanel.stoneClickEvent.emit(stone2, true); + gameControl.abortGame(); + assertTrue(view.handPanel.stoneClickEvent.listeners.isEmpty()); + assertTrue(view.playerPanel.endTurnEvent.listeners.isEmpty()); + } /** */ @Test diff --git a/test/jrummikub/control/turn/AIControlTest.java b/test/jrummikub/control/turn/AIControlTest.java index dca6466..f2c567e 100644 --- a/test/jrummikub/control/turn/AIControlTest.java +++ b/test/jrummikub/control/turn/AIControlTest.java @@ -1,8 +1,12 @@ package jrummikub.control.turn;
-import static org.junit.Assert.*;
+import static jrummikub.model.StoneColor.RED;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.awt.Color;
+import java.util.Arrays;
import jrummikub.control.RoundControl;
import jrummikub.model.GameSettings;
@@ -15,6 +19,7 @@ import jrummikub.model.Position; import jrummikub.model.RoundState;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
+import jrummikub.model.StoneSet;
import jrummikub.util.IListener;
import jrummikub.util.IListener2;
import jrummikub.view.MockView;
@@ -115,4 +120,21 @@ public class AIControlTest { assertEquals(1, roundState.getTable().getSize());
assertEquals(0, roundState.getActivePlayer().getHand().getSize());
}
+
+ @Test
+ public void testWithStonesOnTable() {
+ roundState.getActivePlayer().setLaidOut(true);
+ roundState.getTable().drop(new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED), new Stone(3, RED))), new Position(0,0));
+ IHand hand = roundState.getActivePlayer().getHand();
+ hand.drop(new Stone(4, RED), new Position(0,0));
+ hand.drop(new Stone(7, RED), new Position(0,0));
+ aiControl.setup(new ITurnControl.TurnInfo(roundState,
+ TurnMode.NORMAL_TURN, false), gameSettings, view);
+ aiControl.startTurn();
+ assertTrue(turnEnded);
+ assertFalse(redealt);
+ assertEquals(2, roundState.getTable().getSize());
+ assertEquals(1, roundState.getActivePlayer().getHand().getSize());
+
+ }
}
|