Lorenz Hohmann
3 years ago
2 changed files with 13 additions and 28 deletions
-
17src/main/java/de/tims/fleetstorm/gui/GameLogic.java
-
24src/test/java/de/tims/fleetstorm/gui/LogicTest.java
@ -1,45 +1,27 @@ |
|||
package de.tims.fleetstorm.gui; |
|||
|
|||
import static org.junit.Assert.assertFalse; |
|||
import static org.junit.Assert.assertTrue; |
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import de.tims.fleetstorm.gui.GameLogic; |
|||
|
|||
class LogicTest { |
|||
|
|||
GameLogic guiLogic = new GameLogic(0, 0, 0); |
|||
|
|||
@BeforeEach |
|||
void setup() { |
|||
GameLogic.setGui(new GameLogic(0, 0, 0)); |
|||
guiLogic.start(); |
|||
} |
|||
|
|||
@Test |
|||
void testIfGameStateIsPreparationAfterStart() { |
|||
int expectedState = GameLogic.PREPARATION; |
|||
void testIfGameStateIsRunningAfterStart() { |
|||
int expectedState = GameLogic.RUNNING; |
|||
|
|||
int calculatedState = guiLogic.getGameState(); |
|||
|
|||
assertEquals(expectedState, calculatedState); |
|||
} |
|||
|
|||
@Test |
|||
void testNextMoveIsNotPlayer() { |
|||
|
|||
// 20 tries => every even move is a player move |
|||
for (int i = 0; i < 20; i++) { |
|||
guiLogic.nextMove(); |
|||
boolean calculatedResult = guiLogic.isPlayerMove(); |
|||
if (i % 2 == 0) { |
|||
assertFalse(calculatedResult); |
|||
} else { |
|||
assertTrue(calculatedResult); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue