diff --git a/src/main/java/de/tims/fleetstorm/GameManager.java b/src/main/java/de/tims/fleetstorm/GameManager.java new file mode 100644 index 0000000..8f682cc --- /dev/null +++ b/src/main/java/de/tims/fleetstorm/GameManager.java @@ -0,0 +1,19 @@ +package de.tims.fleetstorm; + +public class GameManager { + + private int gameState; + + public static final int PREPARATION = 1; + public static final int RUNNING = 2; + public static final int OVER = 3; + + public void start() { + this.gameState = GameManager.PREPARATION; + } + + public int getGameState() { + return gameState; + } + +} diff --git a/src/test/java/de/tims/fleetstorm/GameManagerTest.java b/src/test/java/de/tims/fleetstorm/GameManagerTest.java new file mode 100644 index 0000000..d90e85f --- /dev/null +++ b/src/test/java/de/tims/fleetstorm/GameManagerTest.java @@ -0,0 +1,21 @@ +package de.tims.fleetstorm; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class GameManagerTest { + + GameManager gameManager = new GameManager(); + + @Test + void testIfGameStateIsPreparationAfterStart() { + gameManager.start(); + int expectedState = GameManager.PREPARATION; + + int calculatedState = gameManager.getGameState(); + + assertEquals(expectedState, calculatedState); + } + +} diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index 168dade..8eacdae 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -1,66 +1,66 @@ -package de.tims.fleetstorm.matchfield; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertNotNull; - -import java.util.stream.Stream; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -class MatchfieldCreationTest { - - @Test - void testMatchfieldCreateNotEmpty() { - Matchfield matchfield = new Matchfield(0); - int[][] calcResult = matchfield.createMatchfield(); - assertNotNull(calcResult); - } - - @ParameterizedTest(name = "matchfield creation has correct size") - @MethodSource("testMatchfieldSize") - void testMatchfieldCreationHasCorrectSize(String testName, int size, int expectedResult) { - Matchfield matchfield = new Matchfield(size); - matchfield.createMatchfield(); - - int calcResult = matchfield.getSize(); - assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); - } - - static Stream testMatchfieldSize() { - return Stream.of(Arguments.of("field size 10x10", 10, 100), Arguments.of("field size 15x15", 15, 225)); - } - - @ParameterizedTest(name = "matchfield get field is correct") - @MethodSource("testMatchfieldGetFieldState") - void testMatchfieldGetCorrectState(String testName, int x, int y, int expectedResult) { - Matchfield matchfield = new Matchfield(10); - matchfield.createMatchfield(); - - int calcResult = matchfield.getState(x, y); - assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); - } - - static Stream testMatchfieldGetFieldState() { - return Stream.of(Arguments.of("field x:0 y:0 has empty state", 0, 0, Matchfield.EMPTY)); - } - - @ParameterizedTest(name = "matchfield change field is correct") - @MethodSource("testMatchfieldSetStateIsCorrect") - void testMatchfieldGetCorrectState(String testName, int x, int y, int state, int expectedResult) { - Matchfield matchfield = new Matchfield(10); - matchfield.createMatchfield(); - - matchfield.setState(x, y, state); - - int calcResult = matchfield.getState(x, y); - assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); - } - - static Stream testMatchfieldSetStateIsCorrect() { - return Stream.of( - Arguments.of("field x:0 y:0 has state SHIP after setState()", 0, 0, Matchfield.SHIP, Matchfield.SHIP)); - } -} +package de.tims.fleetstorm.matchfield; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class MatchfieldCreationTest { + + @Test + void testMatchfieldCreateNotEmpty() { + Matchfield matchfield = new Matchfield(0); + int[][] calcResult = matchfield.createMatchfield(); + assertNotNull(calcResult); + } + + @ParameterizedTest(name = "matchfield creation has correct size") + @MethodSource("testMatchfieldSize") + void testMatchfieldCreationHasCorrectSize(String testName, int size, int expectedResult) { + Matchfield matchfield = new Matchfield(size); + matchfield.createMatchfield(); + + int calcResult = matchfield.getSize(); + assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream testMatchfieldSize() { + return Stream.of(Arguments.of("field size 10x10", 10, 100), Arguments.of("field size 15x15", 15, 225)); + } + + @ParameterizedTest(name = "matchfield get field is correct") + @MethodSource("testMatchfieldGetFieldState") + void testMatchfieldGetCorrectState(String testName, int x, int y, int expectedResult) { + Matchfield matchfield = new Matchfield(10); + matchfield.createMatchfield(); + + int calcResult = matchfield.getState(x, y); + assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream testMatchfieldGetFieldState() { + return Stream.of(Arguments.of("field x:0 y:0 has empty state", 0, 0, Matchfield.EMPTY)); + } + + @ParameterizedTest(name = "matchfield change field is correct") + @MethodSource("testMatchfieldSetStateIsCorrect") + void testMatchfieldGetCorrectState(String testName, int x, int y, int state, int expectedResult) { + Matchfield matchfield = new Matchfield(10); + matchfield.createMatchfield(); + + matchfield.setState(x, y, state); + + int calcResult = matchfield.getState(x, y); + assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult); + } + + static Stream testMatchfieldSetStateIsCorrect() { + return Stream.of( + Arguments.of("field x:0 y:0 has state SHIP after setState()", 0, 0, Matchfield.SHIP, Matchfield.SHIP)); + } +}