Fix: GameTest
This commit is contained in:
@@ -7,8 +7,10 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -58,14 +60,9 @@ class GameTest {
|
||||
}
|
||||
|
||||
private void resolveAllMandatoryActions(Game game) {
|
||||
int guard = 0;
|
||||
|
||||
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 50) {
|
||||
guard++;
|
||||
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
|
||||
resolveOneMandatoryAction(game);
|
||||
}
|
||||
|
||||
assertTrue(guard < 50, "Possible infinite loop while resolving mandatory actions.");
|
||||
}
|
||||
|
||||
private void resolveOneMandatoryAction(Game game) {
|
||||
@@ -98,14 +95,10 @@ class GameTest {
|
||||
}
|
||||
|
||||
private void resolveActionsUntilOptionalCardEffect(Game game) {
|
||||
int guard = 0;
|
||||
|
||||
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 50) {
|
||||
guard++;
|
||||
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) {
|
||||
resolveOneMandatoryAction(game);
|
||||
}
|
||||
|
||||
assertTrue(guard < 50, "Possible infinite loop while resolving mandatory actions.");
|
||||
assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage());
|
||||
}
|
||||
|
||||
@@ -176,34 +169,24 @@ class GameTest {
|
||||
|
||||
assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage());
|
||||
|
||||
int guard = 0;
|
||||
|
||||
while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS
|
||||
&& !targetPlayer.equals(game.getCurrentState().getCurrentPlayer())
|
||||
&& guard < 20) {
|
||||
guard++;
|
||||
&& !targetPlayer.equals(game.getCurrentState().getCurrentPlayer())) {
|
||||
resolveOneMandatoryAction(game);
|
||||
}
|
||||
|
||||
assertTrue(guard < 20, "Possible infinite loop while reaching target player's slot.");
|
||||
assertEquals(targetPlayer, game.getCurrentState().getCurrentPlayer());
|
||||
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
private void resolveOptionalPhaseIfPresent(Game game) {
|
||||
int guard = 0;
|
||||
|
||||
while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT && guard < 10) {
|
||||
guard++;
|
||||
|
||||
while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) {
|
||||
Player current = game.getCurrentState().getCurrentPlayer();
|
||||
assertNotNull(current);
|
||||
|
||||
assertTrue(game.NoOptionalCard(current));
|
||||
}
|
||||
|
||||
assertTrue(guard < 10, "Possible infinite loop during optional phase.");
|
||||
}
|
||||
|
||||
private void playOneFullRound(Game game) {
|
||||
@@ -322,7 +305,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void slotChoiceByIndexShouldRejectInvalidWrongAndOccupiedSlot() {
|
||||
void shouldRejectInvalidSlotChoices() {
|
||||
Game game = new Game(3);
|
||||
|
||||
Player p1 = new Player("p1");
|
||||
@@ -625,7 +608,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawMethodsShouldRejectWrongStateInvalidIndexesAndWrongPlayer() {
|
||||
void shouldRejectInvalidDrawRequests() {
|
||||
Game game = new Game(3);
|
||||
|
||||
Player p1 = new Player("p1");
|
||||
@@ -767,7 +750,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventResolutionShouldDoNothingOutsideResolvingEventStage() {
|
||||
void eventResolutionIgnoredOutsideItsStage() {
|
||||
Game game = new Game(3);
|
||||
|
||||
assertEquals(GameStages.WAITING, game.getCurrentState().getGameStage());
|
||||
@@ -779,7 +762,7 @@ class GameTest {
|
||||
|
||||
|
||||
@Test
|
||||
void nextRoundShouldIncreaseRound() {
|
||||
void nextRoundIncreasesRound() {
|
||||
Game game = new Game(3);
|
||||
|
||||
int roundBefore = game.getCurrentState().getRound();
|
||||
@@ -888,7 +871,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nextRoundShouldUpdateEraWhenBoardEraDiffersFromCurrentStateEra() {
|
||||
void nextRoundUpdatesEra() {
|
||||
Game game = new Game(3);
|
||||
|
||||
setCurrentStateEra(game, 0);
|
||||
@@ -923,6 +906,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void shouldNotCrashWhenNoPlayerHasOptionalEffect() {
|
||||
Game game = new Game(3);
|
||||
|
||||
@@ -960,7 +944,8 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullGameShouldEndAfterTenRoundsForTwoThreeFourAndFivePlayersUsingOnlyPublicGameFlow() {
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void shouldEndAfterTenRounds() {
|
||||
for (int nPlayers : new int[]{2, 3, 4, 5}) {
|
||||
Game game = new Game(nPlayers);
|
||||
|
||||
@@ -972,10 +957,7 @@ class GameTest {
|
||||
assertEquals(1, game.getCurrentState().getRound());
|
||||
assertNotNull(game.getCurrentState().getCurrentPlayer());
|
||||
|
||||
int guard = 0;
|
||||
|
||||
while (game.getCurrentState().getGameStage() != GameStages.ENDED && guard < 15) {
|
||||
guard++;
|
||||
while (game.getCurrentState().getGameStage() != GameStages.ENDED) {
|
||||
|
||||
int roundBefore = game.getCurrentState().getRound();
|
||||
|
||||
@@ -1013,10 +995,6 @@ class GameTest {
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(
|
||||
guard < 15,
|
||||
"Possible infinite loop while playing the full game with " + nPlayers + " players."
|
||||
);
|
||||
assertEquals(
|
||||
GameStages.ENDED,
|
||||
game.getCurrentState().getGameStage(),
|
||||
@@ -1047,6 +1025,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void roundShouldAdvanceAfterOnlyOptionalPlayerSkipsOptionalCard() {
|
||||
Game game = new Game(3);
|
||||
|
||||
@@ -1070,6 +1049,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void roundShouldAdvanceAfterAllOptionalPlayersSkipOptionalCard() {
|
||||
Game game = new Game(3);
|
||||
|
||||
@@ -1096,6 +1076,7 @@ class GameTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(value = 2, unit = TimeUnit.SECONDS)
|
||||
void fourPlayerGameShouldAllowPlayingSlotG() {
|
||||
Game game = new Game(4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user