Browse Source

Refactor 2-D board array to 1-D array

AIPlayer
Felix Krull 3 years ago
parent
commit
aa521559f6
  1. 4
      src/main/java/Gameboard.java
  2. 18
      src/test/java/GameboardTest.java

4
src/main/java/Gameboard.java

@ -1,8 +1,8 @@
public class Gameboard { public class Gameboard {
int[][] board;
int[] board;
public Gameboard() { public Gameboard() {
board = new int[11][11];
board = new int[11];
} }
} }

18
src/test/java/GameboardTest.java

@ -2,6 +2,11 @@ import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; 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;
import java.util.stream.Stream;
public class GameboardTest { public class GameboardTest {
@ -14,23 +19,22 @@ public class GameboardTest {
@Test @Test
void checkGameboardSize() { void checkGameboardSize() {
String expectedResult = "11, 11";
String currentResult = "" + gb.board.length + ", " + gb.board[0].length;
String expectedResult = "11";
String currentResult = "" + gb.board.length;
assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult); assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult);
} }
@Test @Test
void checkGameboardFilled() { void checkGameboardFilled() {
int[][] expectedGameboard = new int[11][11];
int[] expectedGameboard = new int[11];
for(int i = 0; i < expectedGameboard.length; i++) { for(int i = 0; i < expectedGameboard.length; i++) {
for(int j = 0; j < expectedGameboard[0].length; j++) {
expectedGameboard[i][j] = 0;
}
expectedGameboard[i] = 0;
} }
int [][] givenGameboard = gb.board;
int [] givenGameboard = gb.board;
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard);
} }
} }
Loading…
Cancel
Save