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;
|
||||
|
||||
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 jrummikub.control.RoundControl;
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.GameState;
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.IPlayer;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.model.Player;
|
||||
import jrummikub.model.IRoundState;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.PlayerSettings.Type;
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.RoundState;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneColor;
|
||||
import jrummikub.model.Table;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener3;
|
||||
import jrummikub.util.IListener2;
|
||||
import jrummikub.view.MockView;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -26,10 +28,9 @@ import org.junit.Test;
|
|||
public class AIControlTest {
|
||||
ITurnControl aiControl;
|
||||
|
||||
IRoundState roundState;
|
||||
GameSettings gameSettings;
|
||||
PlayerSettings playerSettings;
|
||||
IPlayer player;
|
||||
ITable table;
|
||||
MockView view;
|
||||
|
||||
boolean turnEnded;
|
||||
|
@ -39,23 +40,24 @@ public class AIControlTest {
|
|||
@Before
|
||||
public void setUp() {
|
||||
aiControl = TurnControlFactory.getFactory(Type.COMPUTER).create();
|
||||
((AIControl) aiControl).useBackgroundThread = false;
|
||||
AIControl.useBackgroundThread = false;
|
||||
gameSettings = new GameSettings();
|
||||
playerSettings = new PlayerSettings("ROBOT_01", Color.GRAY);
|
||||
player = new Player(playerSettings);
|
||||
table = new Table(gameSettings);
|
||||
gameSettings.getPlayerList().add(playerSettings);
|
||||
roundState = new RoundState(gameSettings, new GameState());
|
||||
view = new MockView();
|
||||
turnEnded = false;
|
||||
redealt = false;
|
||||
|
||||
aiControl.getEndOfTurnEvent().add(new IListener3<IHand, ITable, ITable>() {
|
||||
aiControl.getEndOfTurnEvent().add(
|
||||
new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() {
|
||||
@Override
|
||||
public void handle(IHand oldHand, ITable oldTable, ITable newTable) {
|
||||
public void handle(IRoundState state,
|
||||
RoundControl.InvalidTurnInfo value2) {
|
||||
turnEnded = true;
|
||||
roundState = state;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
aiControl.getRedealEvent().add(new IListener() {
|
||||
|
||||
@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(12, StoneColor.RED), new Position(0, 0));
|
||||
hand.drop(new Stone(13, StoneColor.RED), new Position(0, 0));
|
||||
|
@ -77,13 +79,12 @@ public class AIControlTest {
|
|||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testTurnZeroNoRedealing() throws InterruptedException {
|
||||
aiControl.setup(
|
||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
||||
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||
TurnMode.MAY_REDEAL), gameSettings, view);
|
||||
aiControl.startTurn();
|
||||
assertTrue(turnEnded);
|
||||
assertFalse(redealt);
|
||||
assertEquals(table.getSize(), 0);
|
||||
assertEquals(0, roundState.getTable().getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,13 +93,12 @@ public class AIControlTest {
|
|||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testTurnZeroNotMelding() throws InterruptedException {
|
||||
aiControl.setup(
|
||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
||||
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||
TurnMode.INSPECT_ONLY), gameSettings, view);
|
||||
aiControl.startTurn();
|
||||
assertTrue(turnEnded);
|
||||
assertFalse(redealt);
|
||||
assertEquals(table.getSize(), 0);
|
||||
assertEquals(0, roundState.getTable().getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,13 +107,12 @@ public class AIControlTest {
|
|||
*/
|
||||
@Test(timeout = 10000)
|
||||
public void testNormalTurnMelding() throws InterruptedException {
|
||||
aiControl.setup(
|
||||
new ITurnControl.TurnInfo(table, player.getHand(), player.getLaidOut(),
|
||||
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||
TurnMode.NORMAL_TURN), gameSettings, view);
|
||||
aiControl.startTurn();
|
||||
assertTrue(turnEnded);
|
||||
assertFalse(redealt);
|
||||
assertEquals(table.getSize(), 1);
|
||||
assertEquals(player.getHand().getSize(), 0);
|
||||
assertEquals(1, roundState.getTable().getSize());
|
||||
assertEquals(0, roundState.getActivePlayer().getHand().getSize());
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue