Browse Source

Added equals method to ChessFigure with test

feature-chess
Nick Stolbov 3 years ago
parent
commit
c6c9940d8d
  1. 13
      src/main/java/Game/ChessObj/ChessFigure.java
  2. 12
      src/test/java/Game/ChessObj/ChessFigureTest.java

13
src/main/java/Game/ChessObj/ChessFigure.java

@ -61,4 +61,17 @@ public class ChessFigure {
return symbol; return symbol;
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof ChessFigure)) {
return false;
}
ChessFigure x = (ChessFigure) o;
if (this.getType() != x.getType() || this.getTeam() != x.getTeam())
return false;
return true;
}
} }

12
src/test/java/Game/ChessObj/ChessFigureTest.java

@ -31,4 +31,16 @@ class ChessFigureTest {
assertEquals("|Z|", new ChessFigure(ChessFigure.Type.KNIGHT, ChessFigure.Team.BLACK).getSymbol()); assertEquals("|Z|", new ChessFigure(ChessFigure.Type.KNIGHT, ChessFigure.Team.BLACK).getSymbol());
assertEquals("|o|", new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK).getSymbol()); assertEquals("|o|", new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.BLACK).getSymbol());
} }
@Test
void testEquals() {
ChessFigure kw1 = new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.WHITE);
ChessFigure kw2 = new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.WHITE);
ChessFigure kb1 = new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.BLACK);
ChessFigure pw1 = new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE);
assertEquals(kw1, kw2);
assertNotEquals(kw2, kb1);
assertNotEquals(pw1, kb1);
}
} }
Loading…
Cancel
Save