Skip to content

Commit

Permalink
feat : Status Test 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
fucct committed Apr 7, 2020
1 parent 0ba02cc commit 3f688e4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/chess/domain/board/DefaultBoardInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class DefaultBoardInitializer implements BoardInitializer {
@Override
public Map<Position, PieceState> create() {
Map<Position, PieceState> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -44,7 +44,7 @@ public enum DefaultBoard {
private Player player;
private Position position;

DefaultBoard(BiFunction<Position, Player, Piece> generator, Player player, Position position) {
DefaultBoardPiece(BiFunction<Position, Player, Piece> generator, Player player, Position position) {
this.generator = generator;
this.player = player;
this.position = position;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/chess/domain/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ public Player toggle() {
}
return WHITE;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<body>
Hello World!!
</body>
</html>
</html
18 changes: 18 additions & 0 deletions src/test/java/chess/domain/board/ManipulatedBoardInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package chess.domain.board;

import chess.domain.piece.PieceState;
import chess.domain.position.Position;

import java.util.HashMap;
import java.util.Map;

public class ManipulatedBoardInitializer implements BoardInitializer {

@Override
public Map<Position, PieceState> create() {
Map<Position, PieceState> initialBoard = new HashMap<>();
DefaultBoardPiece piece = DefaultBoardPiece.BLACK_ROOK_1;
initialBoard.put(piece.getPosition(), piece.getInitialPiece());
return initialBoard;
}
}
14 changes: 14 additions & 0 deletions src/test/java/chess/domain/player/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
37 changes: 37 additions & 0 deletions src/test/java/chess/domain/result/StatusTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 3f688e4

Please sign in to comment.