From 3f688e432b18bff7035e8f662041782cc9b44493 Mon Sep 17 00:00:00 2001 From: dd Date: Tue, 7 Apr 2020 20:29:41 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Status=20Test=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/board/DefaultBoardInitializer.java | 4 +- ...faultBoard.java => DefaultBoardPiece.java} | 4 +- src/main/java/chess/domain/player/Player.java | 1 - src/main/resources/templates/index.html | 2 +- .../board/ManipulatedBoardInitializer.java | 18 +++++++++ .../java/chess/domain/player/PlayerTest.java | 14 +++++++ .../java/chess/domain/result/StatusTest.java | 37 +++++++++++++++++++ 7 files changed, 74 insertions(+), 6 deletions(-) rename src/main/java/chess/domain/board/{DefaultBoard.java => DefaultBoardPiece.java} (95%) create mode 100644 src/test/java/chess/domain/board/ManipulatedBoardInitializer.java create mode 100644 src/test/java/chess/domain/player/PlayerTest.java create mode 100644 src/test/java/chess/domain/result/StatusTest.java diff --git a/src/main/java/chess/domain/board/DefaultBoardInitializer.java b/src/main/java/chess/domain/board/DefaultBoardInitializer.java index 6fa56fc12a6..c73e28ccac7 100644 --- a/src/main/java/chess/domain/board/DefaultBoardInitializer.java +++ b/src/main/java/chess/domain/board/DefaultBoardInitializer.java @@ -11,8 +11,8 @@ public class DefaultBoardInitializer implements BoardInitializer { @Override public Map create() { Map initialBoard = new HashMap<>(); - for (DefaultBoard pieceRepository : DefaultBoard.values()) { - initialBoard.put(pieceRepository.getPosition(), pieceRepository.getInitialPiece()); + for (DefaultBoardPiece piece : DefaultBoardPiece.values()) { + initialBoard.put(piece.getPosition(), piece.getInitialPiece()); } return initialBoard; } diff --git a/src/main/java/chess/domain/board/DefaultBoard.java b/src/main/java/chess/domain/board/DefaultBoardPiece.java similarity index 95% rename from src/main/java/chess/domain/board/DefaultBoard.java rename to src/main/java/chess/domain/board/DefaultBoardPiece.java index 5bee2dac85f..aeb6e4e5197 100644 --- a/src/main/java/chess/domain/board/DefaultBoard.java +++ b/src/main/java/chess/domain/board/DefaultBoardPiece.java @@ -6,7 +6,7 @@ import java.util.function.BiFunction; -public enum DefaultBoard { +public enum DefaultBoardPiece { BLACK_PAWN_1(NotMovedPawn::of, Player.BLACK, Position.of("A7")), BLACK_PAWN_2(NotMovedPawn::of, Player.BLACK, Position.of("B7")), BLACK_PAWN_3(NotMovedPawn::of, Player.BLACK, Position.of("C7")), @@ -44,7 +44,7 @@ public enum DefaultBoard { private Player player; private Position position; - DefaultBoard(BiFunction generator, Player player, Position position) { + DefaultBoardPiece(BiFunction generator, Player player, Position position) { this.generator = generator; this.player = player; this.position = position; diff --git a/src/main/java/chess/domain/player/Player.java b/src/main/java/chess/domain/player/Player.java index 0077f33a6ce..4926f3d80d7 100644 --- a/src/main/java/chess/domain/player/Player.java +++ b/src/main/java/chess/domain/player/Player.java @@ -10,5 +10,4 @@ public Player toggle() { } return WHITE; } - } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 3a7dbfecdf3..8ca4967bebe 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -7,4 +7,4 @@ Hello World!! - \ No newline at end of file + create() { + Map initialBoard = new HashMap<>(); + DefaultBoardPiece piece = DefaultBoardPiece.BLACK_ROOK_1; + initialBoard.put(piece.getPosition(), piece.getInitialPiece()); + return initialBoard; + } +} diff --git a/src/test/java/chess/domain/player/PlayerTest.java b/src/test/java/chess/domain/player/PlayerTest.java new file mode 100644 index 00000000000..acb86ea7bf3 --- /dev/null +++ b/src/test/java/chess/domain/player/PlayerTest.java @@ -0,0 +1,14 @@ +package chess.domain.player; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class PlayerTest { + + @Test + void toggle() { + assertThat(Player.WHITE.toggle()).isEqualTo(Player.BLACK); + assertThat(Player.BLACK.toggle()).isEqualTo(Player.WHITE); + } +} \ No newline at end of file diff --git a/src/test/java/chess/domain/result/StatusTest.java b/src/test/java/chess/domain/result/StatusTest.java new file mode 100644 index 00000000000..8b263405525 --- /dev/null +++ b/src/test/java/chess/domain/result/StatusTest.java @@ -0,0 +1,37 @@ +package chess.domain.result; + +import chess.domain.board.Board; +import chess.domain.board.DefaultBoardInitializer; +import chess.domain.board.ManipulatedBoardInitializer; +import chess.domain.player.Player; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class StatusTest { + private Board defaultBoard = Board.of(new DefaultBoardInitializer()); + private Board manipulatedBoard = Board.of(new ManipulatedBoardInitializer()); + + @Test + void create() { + assertThat(Status.of(defaultBoard)) + .isInstanceOf(Status.class); + } + + @Test + void defaultStatus() { + assertThat(Status.of(defaultBoard).getStatus().get(Player.BLACK)).isEqualTo(38); + assertThat(Status.of(defaultBoard).getStatus().get(Player.WHITE)).isEqualTo(38); + } + + @Test + void status() { + assertThat(Status.of(manipulatedBoard).getStatus().get(Player.BLACK)).isEqualTo(5); + assertThat(Status.of(manipulatedBoard).getStatus().get(Player.WHITE)).isEqualTo(0); + } + + @Test + void winner() { + assertThat(Status.of(manipulatedBoard).getWinner()).isEqualTo(Player.BLACK); + } +} \ No newline at end of file