From 8612b7e3477dfac31961c98b8927f43861ddaa34 Mon Sep 17 00:00:00 2001 From: Nick Stolbov Date: Sat, 29 Jan 2022 19:28:30 +0100 Subject: [PATCH] Added ChessFigure class with getSymbol method and test --- src/main/java/Game/ChessObj/ChessFigure.java | 64 +++++++++++++++++++ .../java/Game/ChessObj/ChessFigureTest.java | 34 ++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/java/Game/ChessObj/ChessFigure.java create mode 100644 src/test/java/Game/ChessObj/ChessFigureTest.java diff --git a/src/main/java/Game/ChessObj/ChessFigure.java b/src/main/java/Game/ChessObj/ChessFigure.java new file mode 100644 index 0000000..4b097c2 --- /dev/null +++ b/src/main/java/Game/ChessObj/ChessFigure.java @@ -0,0 +1,64 @@ +package Game.ChessObj; + +public class ChessFigure { + + public enum Type { + KING, + QUEEN, + CASTLE, + BISHOP, + KNIGHT, + PAWN + } + + public enum Team { + WHITE, + BLACK + } + + private final Type type; + private final Team team; + + public ChessFigure(Type type, Team team) { + this.type = type; + this.team = team; + } + + public Type getType() { + return this.type; + } + + public Team getTeam() { + return this.team; + } + + public String getSymbol() { + String symbol = ""; + switch(getType()) { + case KING: + symbol = "K"; + break; + case QUEEN: + symbol = "Q"; + break; + case CASTLE: + symbol = "T"; + break; + case BISHOP: + symbol = "I"; + break; + case KNIGHT: + symbol = "Z"; + break; + case PAWN: + symbol = "o"; + break; + default: + } + + symbol = ((this.getTeam()==Team.WHITE)?" ":"|") + symbol + ((this.getTeam()==Team.WHITE)?" ":"|"); + + return symbol; + } + +} diff --git a/src/test/java/Game/ChessObj/ChessFigureTest.java b/src/test/java/Game/ChessObj/ChessFigureTest.java new file mode 100644 index 0000000..384d3f4 --- /dev/null +++ b/src/test/java/Game/ChessObj/ChessFigureTest.java @@ -0,0 +1,34 @@ +package Game.ChessObj; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class ChessFigureTest { + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + @Test + void getSymbol() { + assertEquals(" K ", new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.WHITE).getSymbol()); + assertEquals(" Q ", new ChessFigure(ChessFigure.Type.QUEEN, ChessFigure.Team.WHITE).getSymbol()); + assertEquals(" I ", new ChessFigure(ChessFigure.Type.BISHOP, ChessFigure.Team.WHITE).getSymbol()); + assertEquals(" T ", new ChessFigure(ChessFigure.Type.CASTLE, ChessFigure.Team.WHITE).getSymbol()); + assertEquals(" Z ", new ChessFigure(ChessFigure.Type.KNIGHT, ChessFigure.Team.WHITE).getSymbol()); + assertEquals(" o ", new ChessFigure(ChessFigure.Type.PAWN, ChessFigure.Team.WHITE).getSymbol()); + assertEquals("|K|", new ChessFigure(ChessFigure.Type.KING, ChessFigure.Team.BLACK).getSymbol()); + assertEquals("|Q|", new ChessFigure(ChessFigure.Type.QUEEN, ChessFigure.Team.BLACK).getSymbol()); + assertEquals("|I|", new ChessFigure(ChessFigure.Type.BISHOP, ChessFigure.Team.BLACK).getSymbol()); + assertEquals("|T|", new ChessFigure(ChessFigure.Type.CASTLE, 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()); + } +} \ No newline at end of file