Fix weitere tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@528 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
ec4faf57b1
commit
2a31f0d9a6
1 changed files with 35 additions and 36 deletions
|
@ -1,22 +1,24 @@
|
||||||
package jrummikub.control.turn;
|
package jrummikub.control.turn;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
import jrummikub.control.RoundControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
import jrummikub.model.GameState;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.IPlayer;
|
import jrummikub.model.IRoundState;
|
||||||
import jrummikub.model.ITable;
|
|
||||||
import jrummikub.model.Player;
|
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.PlayerSettings.Type;
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneColor;
|
import jrummikub.model.StoneColor;
|
||||||
import jrummikub.model.Table;
|
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener3;
|
import jrummikub.util.IListener2;
|
||||||
import jrummikub.view.MockView;
|
import jrummikub.view.MockView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -26,10 +28,9 @@ import org.junit.Test;
|
||||||
public class AIControlTest {
|
public class AIControlTest {
|
||||||
ITurnControl aiControl;
|
ITurnControl aiControl;
|
||||||
|
|
||||||
|
IRoundState roundState;
|
||||||
GameSettings gameSettings;
|
GameSettings gameSettings;
|
||||||
PlayerSettings playerSettings;
|
PlayerSettings playerSettings;
|
||||||
IPlayer player;
|
|
||||||
ITable table;
|
|
||||||
MockView view;
|
MockView view;
|
||||||
|
|
||||||
boolean turnEnded;
|
boolean turnEnded;
|
||||||
|
@ -39,23 +40,24 @@ public class AIControlTest {
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create();
|
aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create();
|
||||||
((AIControl) aiControl).useBackgroundThread = false;
|
AIControl.useBackgroundThread = false;
|
||||||
gameSettings = new GameSettings();
|
gameSettings = new GameSettings();
|
||||||
playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
|
playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
|
||||||
player = new Player(playerSettings);
|
gameSettings.getPlayerList().add(playerSettings);
|
||||||
table = new Table(gameSettings);
|
roundState = new RoundState(gameSettings, new GameState());
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
turnEnded = false;
|
turnEnded = false;
|
||||||
redealt = false;
|
redealt = false;
|
||||||
|
|
||||||
aiControl.getEndOfTurnEvent().add(new IListener3<IHand, ITable, ITable>() {
|
aiControl.getEndOfTurnEvent().add(
|
||||||
@Override
|
new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() {
|
||||||
public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
|
@Override
|
||||||
turnEnded = true;
|
public void handle(IRoundState state,
|
||||||
}
|
RoundControl.InvalidTurnInfo value2) {
|
||||||
|
turnEnded = true;
|
||||||
});
|
roundState = state;
|
||||||
|
}
|
||||||
|
});
|
||||||
aiControl.getRedealEvent().add(new IListener() {
|
aiControl.getRedealEvent().add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +67,7 @@ public class AIControlTest {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
IHand hand = player.getHand();
|
IHand hand = roundState.getActivePlayer().getHand();
|
||||||
hand.drop(new Stone(11, StoneColor.RED), new Position(0, 0));
|
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(12, StoneColor.RED), new Position(0, 0));
|
||||||
hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0));
|
hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0));
|
||||||
|
@ -73,47 +75,44 @@ public class AIControlTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* if timeout
|
* if timeout
|
||||||
*/
|
*/
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testTurnZeroNoRedealing() throws InterruptedException {
|
public void testTurnZeroNoRedealing() throws InterruptedException {
|
||||||
aiControl.setup(
|
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
TurnMode.MAY_REDEAL), gameSettings, view);
|
||||||
TurnMode.MAY_REDEAL), gameSettings, view);
|
|
||||||
aiControl.startTurn();
|
aiControl.startTurn();
|
||||||
assertTrue(turnEnded);
|
assertTrue(turnEnded);
|
||||||
assertFalse(redealt);
|
assertFalse(redealt);
|
||||||
assertEquals(table.getSize(), 0);
|
assertEquals(0, roundState.getTable().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* if timeout
|
* if timeout
|
||||||
*/
|
*/
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testTurnZeroNotMelding() throws InterruptedException {
|
public void testTurnZeroNotMelding() throws InterruptedException {
|
||||||
aiControl.setup(
|
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
TurnMode.INSPECT_ONLY), gameSettings, view);
|
||||||
TurnMode.INSPECT_ONLY), gameSettings, view);
|
|
||||||
aiControl.startTurn();
|
aiControl.startTurn();
|
||||||
assertTrue(turnEnded);
|
assertTrue(turnEnded);
|
||||||
assertFalse(redealt);
|
assertFalse(redealt);
|
||||||
assertEquals(table.getSize(), 0);
|
assertEquals(0, roundState.getTable().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
* if timeout
|
* if timeout
|
||||||
*/
|
*/
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testNormalTurnMelding() throws InterruptedException {
|
public void testNormalTurnMelding() throws InterruptedException {
|
||||||
aiControl.setup(
|
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
TurnMode.NORMAL_TURN), gameSettings, view);
|
||||||
TurnMode.NORMAL_TURN), gameSettings, view);
|
|
||||||
aiControl.startTurn();
|
aiControl.startTurn();
|
||||||
assertTrue(turnEnded);
|
assertTrue(turnEnded);
|
||||||
assertFalse(redealt);
|
assertFalse(redealt);
|
||||||
assertEquals(table.getSize(), 1);
|
assertEquals(1, roundState.getTable().getSize());
|
||||||
assertEquals(player.getHand().getSize(), 0);
|
assertEquals(0, roundState.getActivePlayer().getHand().getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue