summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control/turn
diff options
context:
space:
mode:
authorBennet Gerlach <bennet_gerlach@web.de>2011-05-31 23:32:39 +0200
committerBennet Gerlach <bennet_gerlach@web.de>2011-05-31 23:32:39 +0200
commitf343e6dc5ecb243f4292f0e7a4b9cde8dfd379f8 (patch)
treeb98bd31e50f206815d37cda323f654580b6a1d57 /test/jrummikub/control/turn
parent3507bb016a368f342fd6192bc197a4d5ad6d842d (diff)
downloadJRummikub-f343e6dc5ecb243f4292f0e7a4b9cde8dfd379f8.tar
JRummikub-f343e6dc5ecb243f4292f0e7a4b9cde8dfd379f8.zip
Tested BaseAIControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@368 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub/control/turn')
-rw-r--r--test/jrummikub/control/turn/BaseAIControlTest.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/test/jrummikub/control/turn/BaseAIControlTest.java b/test/jrummikub/control/turn/BaseAIControlTest.java
new file mode 100644
index 0000000..dc9998a
--- /dev/null
+++ b/test/jrummikub/control/turn/BaseAIControlTest.java
@@ -0,0 +1,116 @@
+package jrummikub.control.turn;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+
+import java.awt.Color;
+
+import jrummikub.model.GameSettings;
+import jrummikub.model.IHand;
+import jrummikub.model.IPlayer;
+import jrummikub.model.ITable;
+import jrummikub.model.Player;
+import jrummikub.model.PlayerSettings;
+import jrummikub.model.Position;
+import jrummikub.model.Stone;
+import jrummikub.model.StoneColor;
+import jrummikub.model.Table;
+import jrummikub.util.IListener;
+import jrummikub.view.MockView;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/** */
+public class BaseAIControlTest {
+ ITurnControl aiControl;
+
+ GameSettings gameSettings;
+ PlayerSettings playerSettings;
+ IPlayer player;
+ ITable table;
+ MockView view;
+
+ boolean turnEnded;
+ boolean redealt;
+
+ /** */
+ @Before
+ public void setUp() {
+ aiControl = TurnControlFactory.getFactory(TurnControlFactory.Type.COMPUTER)
+ .create();
+ gameSettings = new GameSettings();
+ playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
+ player = new Player(playerSettings);
+ table = new Table(gameSettings);
+ view = new MockView();
+ turnEnded = false;
+ redealt = false;
+
+ aiControl.getEndOfTurnEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ turnEnded = true;
+ }
+
+ });
+
+ aiControl.getRedealEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ redealt = true;
+ }
+
+ });
+
+ IHand hand = player.getHand();
+ hand.drop(new Stone(11, StoneColor.RED), new Position(0, 0));
+ hand.drop(new Stone(12, StoneColor.RED), new Position(0, 0));
+ hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0));
+ }
+
+ /**
+ * @throws InterruptedException
+ */
+ @Test(timeout = 10000)
+ public void testTurnZeroRedealing() throws InterruptedException {
+ aiControl.setup(gameSettings, player, table, view, TurnMode.MAY_REDEAL);
+ aiControl.startTurn();
+ while (!redealt) {
+ Thread.sleep(100);
+ }
+ assertFalse(turnEnded);
+ assertEquals(table.getSize(), 0);
+ }
+
+ /**
+ * @throws InterruptedException
+ */
+ @Test(timeout = 10000)
+ public void testTurnZeroNotMelding() throws InterruptedException {
+ aiControl.setup(gameSettings, player, table, view, TurnMode.INSPECT_ONLY);
+ aiControl.startTurn();
+ while (!turnEnded) {
+ Thread.sleep(100);
+ }
+ assertFalse(redealt);
+ assertEquals(table.getSize(), 0);
+ }
+
+ /**
+ * @throws InterruptedException
+ */
+ @Test(timeout = 10000)
+ public void testNormalTurnMelding() throws InterruptedException {
+ aiControl.setup(gameSettings, player, table, view, TurnMode.NORMAL_TURN);
+ aiControl.startTurn();
+ while (!turnEnded) {
+ Thread.sleep(100);
+ }
+ assertFalse(redealt);
+ assertEquals(table.getSize(), 1);
+ assertEquals(player.getHand().getSize(), 0);
+ }
+}