Fix: GameTest
This commit is contained in:
@@ -55,7 +55,7 @@ class GameTest {
|
||||
|
||||
private void giveOptionalEffectToAllPlayers(Player... players) {
|
||||
for (Player player : players) {
|
||||
player.buildingCards.add(new BuildingCard(12, 1, 1, 0));
|
||||
player.buildingCards.add(new BuildingCard(12, 1, 1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,23 @@ class GameTest {
|
||||
}
|
||||
|
||||
} else {
|
||||
fail("Current player has no drawable cards, although the game is still resolving actions.");
|
||||
fail(
|
||||
"Current player has no drawable cards, although the game is still resolving actions.\n" +
|
||||
"Current player: " + current + "\n" +
|
||||
"Round: " + game.getCurrentState().getRound() + "\n" +
|
||||
"Stage: " + game.getCurrentState().getGameStage() + "\n" +
|
||||
"Slot: " + (game.getCurrentState().getSlot() == null
|
||||
? "null"
|
||||
: game.getCurrentState().getSlot().getSlotId()) + "\n" +
|
||||
"NLower: " + game.getCurrentState().getNLower() + "\n" +
|
||||
"NUpper: " + game.getCurrentState().getNUpper() + "\n" +
|
||||
"Lower tribe size: " + game.getLowerListTribeCards().size() + "\n" +
|
||||
"Upper tribe size: " + game.getUpperListTribeCards().size() + "\n" +
|
||||
"Lower building size: " + game.getLowerListBuilding().size() + "\n" +
|
||||
"Upper building size: " + game.getUpperListBuilding().size() + "\n" +
|
||||
"First lower non-event: " + firstNonEventIndexOrMinusOne(game.getLowerListTribeCards()) + "\n" +
|
||||
"First upper non-event: " + firstNonEventIndexOrMinusOne(game.getUpperListTribeCards())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +132,7 @@ class GameTest {
|
||||
private static class FinalTestBuildingCard extends BuildingCard {
|
||||
|
||||
FinalTestBuildingCard() {
|
||||
super(12, 1, 1, 0);
|
||||
super(12, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -674,7 +690,7 @@ class GameTest {
|
||||
assertNotNull(board);
|
||||
|
||||
board.lowerListBuilding.clear();
|
||||
board.lowerListBuilding.add(new BuildingCard(12, 1, 1, 0));
|
||||
board.lowerListBuilding.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
current.addFood(100);
|
||||
|
||||
@@ -731,6 +747,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void pickOptionalBuildingCardShouldReturnFalseIfPlayerCannotPay() {
|
||||
Game game = new Game(3);
|
||||
|
||||
@@ -744,9 +761,18 @@ class GameTest {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
if (!game.getUpperListBuilding().isEmpty()) {
|
||||
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
||||
while (current.getFoodValue() > 0) {
|
||||
current.removeFood(1);
|
||||
}
|
||||
|
||||
it.polimi.ingsw.gc14.Model.GamePackage.Board board = getBoard(game);
|
||||
assertNotNull(board);
|
||||
|
||||
board.upperListBuilding.clear();
|
||||
board.upperListBuilding.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
assertEquals(0, current.getFoodValue());
|
||||
assertFalse(game.PickOptionalBuildingCard(current, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -835,7 +861,7 @@ class GameTest {
|
||||
assertNotNull(board);
|
||||
|
||||
board.upperListBuilding.clear();
|
||||
board.upperListBuilding.add(new BuildingCard(12, 1, 1, 0));
|
||||
board.upperListBuilding.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
current.addFood(100);
|
||||
|
||||
@@ -856,7 +882,7 @@ class GameTest {
|
||||
assertNotNull(board);
|
||||
|
||||
board.upperListBuilding.clear();
|
||||
board.upperListBuilding.add(new BuildingCard(12, 1, 1, 0));
|
||||
board.upperListBuilding.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
current.addFood(100);
|
||||
|
||||
@@ -944,8 +970,8 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void shouldEndAfterTenRounds() {
|
||||
@Timeout(value = 10, unit = TimeUnit.SECONDS)
|
||||
void shouldCompleteFullGameThroughRealFlow() {
|
||||
for (int nPlayers : new int[]{2, 3, 4, 5}) {
|
||||
Game game = new Game(nPlayers);
|
||||
|
||||
@@ -957,54 +983,42 @@ class GameTest {
|
||||
assertEquals(1, game.getCurrentState().getRound());
|
||||
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||
|
||||
while (game.getCurrentState().getGameStage() != GameStages.ENDED) {
|
||||
|
||||
int roundBefore = game.getCurrentState().getRound();
|
||||
for (int expectedRound = 1; expectedRound < 10; expectedRound++) {
|
||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||
assertEquals(expectedRound, game.getCurrentState().getRound());
|
||||
|
||||
playOneFullRound(game);
|
||||
|
||||
if (roundBefore < 10) {
|
||||
assertEquals(
|
||||
GameStages.SLOT_CHOICE,
|
||||
game.getCurrentState().getGameStage(),
|
||||
"After a non-final round, the game must return to SLOT_CHOICE."
|
||||
);
|
||||
assertEquals(
|
||||
GameStages.SLOT_CHOICE,
|
||||
game.getCurrentState().getGameStage(),
|
||||
"After round " + expectedRound + ", the game should return to SLOT_CHOICE."
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
roundBefore + 1,
|
||||
game.getCurrentState().getRound(),
|
||||
"The round number must increase by one after each completed round."
|
||||
);
|
||||
assertEquals(
|
||||
expectedRound + 1,
|
||||
game.getCurrentState().getRound(),
|
||||
"The round should increase after completing round " + expectedRound + "."
|
||||
);
|
||||
|
||||
assertNotNull(
|
||||
game.getCurrentState().getCurrentPlayer(),
|
||||
"At the beginning of the next round there must be a current player."
|
||||
);
|
||||
} else {
|
||||
assertEquals(
|
||||
GameStages.ENDED,
|
||||
game.getCurrentState().getGameStage(),
|
||||
"After round 10, the game must end."
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
10,
|
||||
game.getCurrentState().getRound(),
|
||||
"The game must end at round 10."
|
||||
);
|
||||
}
|
||||
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||
}
|
||||
|
||||
assertEquals(10, game.getCurrentState().getRound());
|
||||
assertEquals(GameStages.SLOT_CHOICE, game.getCurrentState().getGameStage());
|
||||
|
||||
playOneFullRound(game);
|
||||
|
||||
assertEquals(
|
||||
GameStages.ENDED,
|
||||
game.getCurrentState().getGameStage(),
|
||||
"The game must end after round 10 with " + nPlayers + " players."
|
||||
"The game should end after completing round 10 with " + nPlayers + " players."
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
10,
|
||||
game.getCurrentState().getRound(),
|
||||
"The game must end at round 10 with " + nPlayers + " players."
|
||||
"The game should end at round 10 with " + nPlayers + " players."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1031,7 +1045,7 @@ class GameTest {
|
||||
|
||||
List<Player> players = addPlayers(game, 3, "single_optional_");
|
||||
|
||||
players.get(0).buildingCards.add(new BuildingCard(12, 1, 1, 0));
|
||||
players.get(0).buildingCards.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
int roundBefore = game.getCurrentState().getRound();
|
||||
|
||||
@@ -1110,5 +1124,64 @@ class GameTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void pickOptionalTribeCardShouldRejectEventCard() {
|
||||
Game game = new Game(3);
|
||||
|
||||
Player p1 = new Player("p1");
|
||||
Player p2 = new Player("p2");
|
||||
Player p3 = new Player("p3");
|
||||
|
||||
assertTrue(game.addPlayer(p1));
|
||||
assertTrue(game.addPlayer(p2));
|
||||
assertTrue(game.addPlayer(p3));
|
||||
|
||||
giveOptionalEffectToAllPlayers(p1, p2, p3);
|
||||
|
||||
completeSlotChoice(game);
|
||||
resolveActionsUntilOptionalCardEffect(game);
|
||||
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
it.polimi.ingsw.gc14.Model.GamePackage.Board board = getBoard(game);
|
||||
assertNotNull(board);
|
||||
|
||||
board.upperListTribe.add(0,
|
||||
new it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance(1, 3));
|
||||
|
||||
assertTrue(board.upperListTribe.get(0).IsEventCard());
|
||||
assertFalse(game.PickOptionalTribeCardByIndex(current, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawLowerBuildingCardShouldRejectWrongPlayer() {
|
||||
Game game = new Game(3);
|
||||
|
||||
Player p1 = new Player("p1");
|
||||
Player p2 = new Player("p2");
|
||||
Player p3 = new Player("p3");
|
||||
|
||||
assertTrue(game.addPlayer(p1));
|
||||
assertTrue(game.addPlayer(p2));
|
||||
assertTrue(game.addPlayer(p3));
|
||||
|
||||
Player current = completeSlotChoiceAndAdvanceToPlayerOnSlot(game, 'D');
|
||||
assertNotNull(current);
|
||||
|
||||
Player wrongPlayer = current.equals(p1) ? p2 : p1;
|
||||
|
||||
it.polimi.ingsw.gc14.Model.GamePackage.Board board = getBoard(game);
|
||||
assertNotNull(board);
|
||||
|
||||
board.lowerListBuilding.clear();
|
||||
board.lowerListBuilding.add(new BuildingCard(12, 1, 1, 1));
|
||||
|
||||
wrongPlayer.addFood(100);
|
||||
|
||||
assertFalse(game.DrawLowerBuildingCardByIndex(wrongPlayer, 0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user