Skip to content

Commit

Permalink
refactor : 설계 리팩토링
Browse files Browse the repository at this point in the history
              - 컨벤션 리팩토링
              - 테스트 에러 수정
  • Loading branch information
fucct committed Mar 30, 2020
1 parent 3eb19bf commit 3e7ee5a
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/main/java/chess/controller/ChessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.stream.Collectors;

public class ChessController {

private ChessGame chessGame = new ChessGame();

public void run() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/chess/controller/dto/Command.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package chess.controller.dto;

public enum Command {

START,
END,
MOVE,
Expand Down
1 change: 0 additions & 1 deletion src/main/java/chess/domain/ChessGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import chess.domain.state.State;

public class ChessGame {

private State state;
private Turn turn = Turn.from(Player.WHITE);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/chess/domain/MovingDirection.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static MovingDirection getDirection(Position source, Position target) {
.filter(direction -> direction.isSameFileDirection(fileDifference))
.filter(direction -> direction.isSameRankDirection(rankDifference))
.findFirst()
.orElseThrow(() -> new MovingDirectionException());
.orElseThrow(MovingDirectionException::new);
}

private boolean isSameDirection(Double tangent) {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/chess/domain/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.stream.Collectors;

public class Board {

private Map<Position, PieceState> board;

private Board(Map<Position, PieceState> board) {
Expand Down Expand Up @@ -50,7 +49,7 @@ private Map<Position, PieceDto> getBoardDto() {
return board.entrySet()
.stream()
.collect(Collectors.toMap(
entry -> entry.getKey(),
Map.Entry::getKey,
entry -> new PieceDto(entry.getValue().getPlayer())
));
}
Expand All @@ -60,16 +59,14 @@ public Map<Position, PieceState> getRemainPieces(Player player) {
.stream()
.filter(entry -> player.equals(entry.getValue().getPlayer()))
.collect(Collectors.toMap(
entry -> entry.getKey(),
entry -> entry.getValue()
Map.Entry::getKey,
Map.Entry::getValue
));
}

public boolean isLost(Player player) {
return board.values()
.stream()
.filter(piece -> player.equals(piece.getPlayer()))
.filter(piece -> piece instanceof King)
.count() == 0;
.noneMatch(piece -> player.equals(piece.getPlayer()) && piece instanceof King);
}
}
2 changes: 0 additions & 2 deletions src/main/java/chess/domain/board/BoardInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
import java.util.Map;

public interface BoardInitializer {

Map<Position, PieceState> create();

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.function.BiFunction;

public enum InitialPieceRepository {

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
1 change: 0 additions & 1 deletion src/main/java/chess/domain/player/Player.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package chess.domain.player;

public enum Player {

WHITE,
BLACK;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/chess/domain/state/ReadyState.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public Map<Position, PieceState> getRemainPiece(Player player) {
}

@Override
public State status() {
public Status getStatus() {
throw new UnsupportedOperationException("아직 게임이 시작되지 않았습니다.");
}

@Override
public Status getStatus() {
public State status() {
throw new UnsupportedOperationException("아직 게임이 시작되지 않았습니다.");
}
}
12 changes: 6 additions & 6 deletions src/main/java/chess/domain/state/RunningState.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@ public State move(MoveParameter moveParameter, Turn turn) {

@Override
public State end() {
return new EndState(getStatus());
return new EndState(createStatus());
}

@Override
public State status() {
return new EndState(createStatus());
}

@Override
public Status getStatus() {
throw new UnsupportedOperationException("아직 게임이 종료되지 않았습니다.");
}

public Status createStatus() {
Map<Player, Double> status = new HashMap<>();
double blackSum = 0;
Expand Down Expand Up @@ -95,6 +90,11 @@ public Map<Position, PieceState> getRemainPiece(Player player) {
return board.getRemainPieces(player);
}

@Override
public Status getStatus() {
throw new UnsupportedOperationException("게임이 아직 종료되지 않았습니다.");
}

private double getPawnPointsByFile(File file, Player player) {

/* 해당 file의 PAWN 점수합을 계산한다 */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/chess/domain/state/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public interface State {

State end();

Board getBoard();
State status();

boolean isEnd();

Map<Position, PieceState> getRemainPiece(Player player);
Board getBoard();

State status();
Map<Position, PieceState> getRemainPiece(Player player);

Status getStatus();
}
1 change: 0 additions & 1 deletion src/main/java/chess/view/InputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Scanner;

public class InputView {

private static final int COMMAND_INDEX = 0;
private static final int PARAMETER_START_INDEX = 1;
private static final String COMMAND_DELIMITER = " ";
Expand Down
28 changes: 20 additions & 8 deletions src/test/java/chess/domain/state/EndStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import chess.domain.MoveParameter;
import chess.domain.Turn;
import chess.domain.board.Board;
import chess.domain.board.EnumRepositoryBoardInitializer;
import chess.domain.player.Player;
import chess.domain.result.Status;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

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

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -18,16 +19,20 @@ class EndStateTest {

EndState endState;


@BeforeEach
void setUp() {
endState = new EndState(Board.of(new EnumRepositoryBoardInitializer()));
Map<Player, Double> status = new HashMap<>();
status.put(Player.WHITE, 0d);
status.put(Player.BLACK, 0d);
endState = new EndState(new Status(status));
}

@Test
@DisplayName("EndState는 기존의 board를 가지고 게임을 다시 시작")
@DisplayName("EndState는 Start 불가능")
void start() {
assertThat(endState.start())
.isInstanceOf(RunningState.class);
assertThatThrownBy(() -> endState.start())
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
Expand All @@ -47,7 +52,14 @@ void end() {
@Test
@DisplayName("EndState는 getBoard 메서드를 지원하지 않음")
void getBoard() {
assertThat(endState.getBoard())
.isInstanceOf(Board.class);
assertThatThrownBy(() -> endState.getBoard())
.isInstanceOf(UnsupportedOperationException.class);
}

@Test
@DisplayName("EndState는 getStatus 시 결과를 반환함")
void getStatus() {
assertThat(endState.getStatus())
.isInstanceOf(Status.class);
}
}

0 comments on commit 3e7ee5a

Please sign in to comment.