summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 10:38:10 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 10:38:10 +0200
commitf5aa073827980bdae3e530b6ea9d8c17807ad764 (patch)
tree8d64a1816516a152b03868c14bee551474690c28
parente1df2b8e8866280f62159a5bc70d9aca390ca9bf (diff)
downloadJRummikub-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
-rw-r--r--mock/jrummikub/view/MockHandPanel.java3
-rw-r--r--src/jrummikub/control/turn/AIControl.java2
-rw-r--r--test/jrummikub/control/GameControlTest.java80
-rw-r--r--test/jrummikub/control/turn/AIControlTest.java24
4 files changed, 107 insertions, 2 deletions
diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java
index 3ede846..863bb57 100644
--- a/mock/jrummikub/view/MockHandPanel.java
+++ b/mock/jrummikub/view/MockHandPanel.java
@@ -9,6 +9,7 @@ import jrummikub.util.Event1;
import jrummikub.util.Event2;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
+import jrummikub.util.MockEvent2;
import jrummikub.util.Pair;
/**
@@ -16,7 +17,7 @@ import jrummikub.util.Pair;
*/
public class MockHandPanel implements IHandPanel {
/** */
- public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
+ public MockEvent2<Stone, Boolean> stoneClickEvent = new MockEvent2<Stone, Boolean>();
/** */
public List<Pair<Stone, Position>> stones;
/** */
diff --git a/src/jrummikub/control/turn/AIControl.java b/src/jrummikub/control/turn/AIControl.java
index 9ce162f..f326075 100644
--- a/src/jrummikub/control/turn/AIControl.java
+++ b/src/jrummikub/control/turn/AIControl.java
@@ -18,6 +18,8 @@ import jrummikub.util.Pair;
/**
* Base class for AI players
*
+ * Code not covered by tests uses timers and background threads.
+ *
*/
public class AIControl extends AbstractTurnControl {
private TurnLogic logic;
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());
+
+ }
}