Browse Source

added equals method for Board with test

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

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

@ -34,6 +34,8 @@ public class Board {
} }
} }
/* /*
1 2 3 1 2 3
o x o o x o
@ -63,4 +65,18 @@ public class Board {
public State[] getStates() { public State[] getStates() {
return this.states; return this.states;
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof Board)) {
return false;
}
Board x = (Board)o;
for (int i = 0; i < x.getStates().length; i++) {
if (this.getStates()[i] != x.getStates()[i]) {
return false;
}
}
return true;
}
} }

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

@ -35,5 +35,15 @@ class BoardTest {
} }
@SuppressWarnings("AssertBetweenInconvertibleTypes")
@Test
void testEquals() {
assertNotEquals(board, "Test");
Board secondBoard = new Board();
assertEquals(board, secondBoard);
secondBoard.getStates()[0] = Board.State.CROSS;
assertNotEquals(board, secondBoard);
board.getStates()[0] = Board.State.CROSS;
assertEquals(board, secondBoard);
}
} }
Loading…
Cancel
Save