diff --git a/src/main/java/Game/ChessObj/ChessFigure.java b/src/main/java/Game/ChessObj/ChessFigure.java index 4b097c2..efa4d6e 100644 --- a/src/main/java/Game/ChessObj/ChessFigure.java +++ b/src/main/java/Game/ChessObj/ChessFigure.java @@ -34,7 +34,7 @@ public class ChessFigure { public String getSymbol() { String symbol = ""; - switch(getType()) { + switch (getType()) { case KING: symbol = "K"; break; @@ -56,9 +56,22 @@ public class ChessFigure { default: } - symbol = ((this.getTeam()==Team.WHITE)?" ":"|") + symbol + ((this.getTeam()==Team.WHITE)?" ":"|"); + symbol = ((this.getTeam() == Team.WHITE) ? " " : "|") + symbol + ((this.getTeam() == Team.WHITE) ? " " : "|"); - 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; } } diff --git a/src/test/java/Game/ChessObj/ChessFigureTest.java b/src/test/java/Game/ChessObj/ChessFigureTest.java index 384d3f4..866eb12 100644 --- a/src/test/java/Game/ChessObj/ChessFigureTest.java +++ b/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("|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); + } } \ No newline at end of file