Browse Source

tictactoe: fixed fieldCountTest. Now works with different playfield sizes

tictactoe
Malte Schellhardt 3 years ago
committed by Lorenz Hohmann
parent
commit
edbbefc7ff
  1. 2
      src/main/java/de/tims/tictactoe/GameLogic.java
  2. 31
      src/test/java/de/tims/tictactoe/GameLogicTest.java

2
src/main/java/de/tims/tictactoe/GameLogic.java

@ -14,7 +14,7 @@ public class GameLogic {
public int countFields() {
// TODO Auto-generated method stub
return 9;
return this.board[0].length * this.board.length;
}
}

31
src/test/java/de/tims/tictactoe/GameLogicTest.java

@ -1,10 +1,16 @@
package de.tims.tictactoe;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
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 GameLogicTest {
@ -35,12 +41,21 @@ class GameLogicTest {
assertArrayEquals(expectedResult, realResult);
}
@Test
void fieldCountTest() {
int expectedResult = 9;
int realResult = game.countFields();
assertEquals(expectedResult, realResult);
}
@ParameterizedTest(name = "[{index}] {0} -> {1}")
@MethodSource("testCasesForCountPlayfields")
void fieldCountTest(String testName, int size, int expectedResult) {
GameLogic game = new GameLogic(size);
int realResult = game.countFields();
assertEquals(expectedResult, realResult);
}
private static Stream<Arguments> testCasesForCountPlayfields() {
return Stream.of(
Arguments.of("3x3 board with 9 playfields", 3, 9),
Arguments.of("4x4 board with 16 playfields", 4, 16),
Arguments.of("5x5 board with 25 playfields", 5,25)
);
}
}
Loading…
Cancel
Save