Browse Source

matchfield: added field size

matchfield
Lorenz Hohmann 2 years ago
parent
commit
08ba5092ce
  1. 16
      src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java
  2. 20
      src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

16
src/main/java/de/tims/fleetstorm/matchfield/MatchfieldCreation.java

@ -2,8 +2,20 @@ package de.tims.fleetstorm.matchfield;
public class MatchfieldCreation {
public int[][] createMatchfield() {
return new int[][] {};
public int[][] createMatchfield(int size) {
int[][] matchfield = new int[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
matchfield[i][j] = 1;
}
}
return matchfield;
}
public int getSize() {
return 10;
}
}

20
src/test/java/de/tims/fleetstorm/matchfield/MatchfieldCreationTest.java

@ -1,8 +1,14 @@
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 {
@ -10,7 +16,19 @@ class MatchfieldCreationTest {
@Test
void testMatchfieldCreateNotEmpty() {
int[][] calcResult = matchfield.createMatchfield();
int[][] calcResult = matchfield.createMatchfield(0);
assertNotNull(calcResult);
}
@ParameterizedTest(name = "matchfield creation has correct size")
@MethodSource("testMatchfieldSize")
void testMatchfieldCreationHasCorrectSize(String testName, int size, int expectedResult) {
matchfield.createMatchfield(size);
int calcResult = matchfield.getSize();
assertThat(calcResult).describedAs(testName).isEqualTo(expectedResult);
}
static Stream<Arguments> testMatchfieldSize() {
return Stream.of(Arguments.of("field size 10x10", 10, 10));
}
}
Loading…
Cancel
Save