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