diff --git a/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java b/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java index c101ca2..ed3da8c 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java @@ -2,20 +2,27 @@ package de.tims.fleetstorm.matchfield; public class MatchfieldCreation { - public int[][] createMatchfield(int size) { - int[][] matchfield = new int[size][size]; + private int[][] matchfield; + private int size; + + public MatchfieldCreation(int size) { + this.size = size; + } + + public int[][] createMatchfield() { + this.matchfield = new int[this.size][this.size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { - matchfield[i][j] = 1; + this.matchfield[i][j] = 1; } } - return matchfield; + return this.matchfield; } public int getSize() { - return 10; + return this.matchfield.length * this.matchfield[0].length; } } diff --git a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java index e285b46..79b0047 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java @@ -12,23 +12,24 @@ import org.junit.jupiter.params.provider.MethodSource; class MatchfieldCreationTest { - MatchfieldCreation matchfield = new MatchfieldCreation(); - @Test void testMatchfieldCreateNotEmpty() { - int[][] calcResult = matchfield.createMatchfield(0); + MatchfieldCreation matchfield = new MatchfieldCreation(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.createMatchfield(size); + MatchfieldCreation matchfield = new MatchfieldCreation(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, 10)); + return Stream.of(Arguments.of("field size 10x10", 10, 100), Arguments.of("field size 15x15", 15, 225)); } }