Browse Source

Added setCellState to class Board with test

feature-game
Dion Aliu 3 years ago
parent
commit
9560dfb178
  1. 12
      src/main/java/Game/TicTacToe/Board.java
  2. 13
      src/test/java/Game/TicTacToe/BoardTest.java

12
src/main/java/Game/TicTacToe/Board.java

@ -34,6 +34,18 @@ public class Board {
} }
} }
public void setCellState(int cell, boolean cross) {
if (cell <= 9 && cell >= 1) {
if (this.states[cell-1] != State.EMPTY) {
return;
}
if (cross) {
this.states[cell-1] = State.CROSS;
} else {
this.states[cell-1] = State.CIRCLE;
}
}
}
/* /*

13
src/test/java/Game/TicTacToe/BoardTest.java

@ -5,6 +5,8 @@ import org.junit.jupiter.api.AfterEach;
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 java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class BoardTest { class BoardTest {
@ -34,6 +36,17 @@ class BoardTest {
} }
} }
@Test
void setCellState() {
Board.State[] lastBoard = Arrays.copyOf(board.getStates(), board.getStates().length);
board.setCellState(1, true);
assertFalse(Arrays.equals(lastBoard, board.getStates()));
assertEquals(board.getStates()[0], Board.State.CROSS);
board.setCellState(1, false);
assertEquals(board.getStates()[0], Board.State.CROSS);
board.setCellState(2, false);
assertEquals(board.getStates()[1], Board.State.CIRCLE);
}
@SuppressWarnings("AssertBetweenInconvertibleTypes") @SuppressWarnings("AssertBetweenInconvertibleTypes")
@Test @Test

Loading…
Cancel
Save