From aa521559f6f7c8b51dbab6ec7b71d5eee285cf31 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 11 Jan 2022 09:52:56 +0100 Subject: [PATCH] Refactor 2-D board array to 1-D array --- src/main/java/Gameboard.java | 4 ++-- src/test/java/GameboardTest.java | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java index 9dc4cd4..8ffdcd0 100644 --- a/src/main/java/Gameboard.java +++ b/src/main/java/Gameboard.java @@ -1,8 +1,8 @@ public class Gameboard { - int[][] board; + int[] board; public Gameboard() { - board = new int[11][11]; + board = new int[11]; } } diff --git a/src/test/java/GameboardTest.java b/src/test/java/GameboardTest.java index f5b38ac..052c9b4 100644 --- a/src/test/java/GameboardTest.java +++ b/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.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 { @@ -14,23 +19,22 @@ public class GameboardTest { @Test 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); } @Test void checkGameboardFilled() { - int[][] expectedGameboard = new int[11][11]; + int[] expectedGameboard = new int[11]; 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); } + }