-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1단계 - 사다리 생성] 제이(이재윤) 미션 제출합니다. #112
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7d4b52f
docs: 기능구현목록 초안 작성
sosow0212 776c4c6
feat: Name에 대한 예외 로직 작성
sosow0212 da9d985
feat: Player 생성 로직 추가
sosow0212 3623a53
feat: Players 예외처리 및 가장 긴 이름 반환하는 로직 구현
sosow0212 fa48dea
feat: 사다리 높이에 대한 예외 로직 추가
sosow0212 525e8a3
feat: 발판 생성 기능 구현
sosow0212 b19130b
feat: 사다리의 각 Line을 생성 기능 구현
sosow0212 4a22c99
feat: 사다리 생성 기능 구현
sosow0212 2c159d1
feat: 높이와 너비를 가지는 Ladder도메인 생성
sosow0212 5e37d3b
feat: 입력을 받기 위한 기능 구현
sosow0212 be28c1b
refactor: players의 생성자 매개변수 타입 변경
sosow0212 f668103
feat: 컨트롤러에서 도메인 초기화 기능 구현
sosow0212 3338518
feat: 사다리타기 결과 출력 구현 (리팩토링 전)
sosow0212 09a7aac
refactor: OutputView 메서드 분리
sosow0212 38060ee
refactor: PlayerName에 대한 메서드 분리, 리네이밍, 예외메시지 추가
sosow0212 8ece83b
refactor: Players에 대한 메서드 분리, 예외메시지 추가
sosow0212 fd87cf9
refactor: 사다리 높이 메서드 분리 및 예외 메시지 추가
sosow0212 fb926f8
refactor: Lines, Line 리네이밍 작업
sosow0212 6a9e343
refactor: 테스트를 위한 Lines 생성자 추가 및 메서드 분리, 테스트 리팩토링 작업
sosow0212 d3762e8
refactor: Line 메서드 분리 및 리네이밍 진행
sosow0212 08f3d76
feat: 최대 사다리 높이에 대한 예외처리 추가
sosow0212 62e068c
refactor: OutputView 출력 로직 수정
sosow0212 6e40af6
refactor: OutputView 플레이어 출력 로직 리팩토링
sosow0212 66105bc
feat: 사다리 구성에 필요한 기호를 반환해주는 Enum 생성
sosow0212 ff1c578
메서드 분리 작업 및 리네이밍 진행
sosow0212 e9db312
docs: 기능 구현 목록 최신화
sosow0212 fe2fedd
refactor: 테스트 메서드 리네이밍 및 테스트 추가
sosow0212 6821eda
refactor: Ladder 테스트 생성
sosow0212 d942937
refactor: Ladder 생성자를 필드에 있는 객체로 받게 리팩토링 진행
sosow0212 220adf4
refactor: 방어적 복사를 통해 반환되는 Collection타입의 값을 외부에서 변경하지 못하게 변경
sosow0212 53d1cf6
test: 예외 테스트에서, 정상적인 값이 들어온 경우의 케이스도 추가
sosow0212 ec22043
refactor: 변수명 통일
sosow0212 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import controller.LadderGameController; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
LadderGameController ladderGameController = new LadderGameController(); | ||
ladderGameController.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controller; | ||
|
||
import domain.Height; | ||
import domain.Ladder; | ||
import domain.Lines; | ||
import domain.Players; | ||
import java.util.List; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
public class LadderGameController { | ||
|
||
private final InputView inputView; | ||
private final OutputView outputView; | ||
|
||
public LadderGameController() { | ||
this.inputView = new InputView(); | ||
this.outputView = new OutputView(); | ||
} | ||
|
||
public void run() { | ||
Players players = makePlayers(); | ||
Ladder ladder = makeLadder(players.findNumberOfPlayers()); | ||
|
||
outputView.printResult(players, ladder); | ||
} | ||
|
||
private Players makePlayers() { | ||
try { | ||
List<String> playerNames = inputView.readPlayerNames(); | ||
return new Players(playerNames); | ||
} catch (IllegalArgumentException exception) { | ||
System.out.println(exception.getMessage()); | ||
return makePlayers(); | ||
} | ||
} | ||
|
||
private Ladder makeLadder(int numberOfPlayers) { | ||
try { | ||
int ladderHeight = inputView.readHeight(); | ||
Ladder ladder = new Ladder(new Lines(numberOfPlayers, ladderHeight), new Height(ladderHeight)); | ||
return ladder; | ||
} catch (IllegalArgumentException exception) { | ||
System.out.println(exception.getMessage()); | ||
return makeLadder(numberOfPlayers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package domain; | ||
|
||
public class Height { | ||
|
||
private static final int MINIMUM_LENGTH_OF_HEIGHT = 1; | ||
private static final int MAXIMUM_LENGTH_OF_HEIGHT = 10; | ||
|
||
private final int height; | ||
|
||
public Height(final int height) { | ||
validateLengthOfHeight(height); | ||
this.height = height; | ||
} | ||
|
||
private void validateLengthOfHeight(final int height) { | ||
if (isNotPermittedLengthOfHeight(height)) { | ||
throw new IllegalArgumentException("사다리의 높이는 최소 1이상 최대 10이하입니다."); | ||
} | ||
} | ||
|
||
private boolean isNotPermittedLengthOfHeight(int height) { | ||
return (height < MINIMUM_LENGTH_OF_HEIGHT) || (height > MAXIMUM_LENGTH_OF_HEIGHT); | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package domain; | ||
|
||
public class Ladder { | ||
|
||
private final Lines lines; | ||
private final Height height; | ||
|
||
public Ladder(final Lines lines, final Height height) { | ||
this.lines = lines; | ||
this.height = height; | ||
} | ||
|
||
public int findLadderHeight() { | ||
return this.height.getHeight(); | ||
} | ||
|
||
public Lines getLines() { | ||
return lines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum LadderSymbol { | ||
|
||
BLANK(" "), | ||
FOOTHOLD("-"), | ||
BAR("|"); | ||
|
||
private final String symbol; | ||
|
||
LadderSymbol(final String symbol) { | ||
this.symbol = symbol; | ||
} | ||
|
||
public static String draw(final String symbol, final int repeatedNumber) { | ||
return find(symbol).symbol.repeat(repeatedNumber); | ||
} | ||
|
||
private static LadderSymbol find(final String symbol) { | ||
return Arrays.stream(values()) | ||
.filter(value -> value.symbol.equals(symbol)) | ||
.findAny() | ||
.orElseThrow(IllegalArgumentException::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import utils.FootholdGenerator; | ||
|
||
public class Line { | ||
|
||
private final List<Boolean> footholds; | ||
|
||
public Line(final int numberOfPlayer, final FootholdGenerator footholdGenerator) { | ||
footholds = makeFootholds(numberOfPlayer, footholdGenerator); | ||
} | ||
|
||
private List<Boolean> makeFootholds(final int numberOfPlayer, final FootholdGenerator footholdGenerator) { | ||
List<Boolean> footholds = new ArrayList<>(); | ||
|
||
generateFootholds(footholdGenerator, footholds, numberOfPlayer); | ||
|
||
return footholds; | ||
} | ||
|
||
private void generateFootholds(final FootholdGenerator footholdGenerator, final List<Boolean> footholds, | ||
final int numberOfPlayer) { | ||
int numberOfPoint = numberOfPlayer - 1; | ||
|
||
createFirstFoothold(footholds, footholdGenerator); | ||
createOtherFootholds(footholdGenerator, footholds, numberOfPoint); | ||
} | ||
|
||
private void createFirstFoothold(final List<Boolean> points, final FootholdGenerator footholdGenerator) { | ||
points.add(footholdGenerator.generate()); | ||
} | ||
|
||
private void createOtherFootholds(final FootholdGenerator footholdGenerator, final List<Boolean> footholds, | ||
final int numberOfPoint) { | ||
for (int i = 1; i < numberOfPoint; i++) { | ||
boolean isExistFoothold = footholdGenerator.generate(); | ||
createFootholdWithoutFirst(footholds, i, isExistFoothold); | ||
} | ||
} | ||
|
||
private void createFootholdWithoutFirst(final List<Boolean> points, final int index, final boolean isExistFoothold) { | ||
if (isConsecutiveExistingFoothold(points, index, isExistFoothold)) { | ||
points.add(false); | ||
return; | ||
} | ||
points.add(isExistFoothold); | ||
} | ||
|
||
private boolean isConsecutiveExistingFoothold(final List<Boolean> points, final int index, final boolean random) { | ||
return points.get(index - 1) && random; | ||
} | ||
|
||
public List<Boolean> getFootholds() { | ||
return footholds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import utils.RandomFootholdGenerator; | ||
|
||
public class Lines { | ||
|
||
private final List<Line> lines; | ||
|
||
public Lines(final int numberOfPlayer, final int height) { | ||
this.lines = makeLines(numberOfPlayer, height); | ||
} | ||
|
||
public Lines(final List<Line> lines) { | ||
this.lines = lines; | ||
} | ||
|
||
private List<Line> makeLines(final int numberOfPlayer, final int height) { | ||
List<Line> lines = new ArrayList<>(); | ||
|
||
for (int i = 0; i < height; i++) { | ||
lines.add(new Line(numberOfPlayer, new RandomFootholdGenerator())); | ||
} | ||
|
||
return lines; | ||
} | ||
|
||
public List<Boolean> findSelectedLine(final int selectedPosition) { | ||
return this.lines.get(selectedPosition).getFootholds(); | ||
} | ||
|
||
public List<Line> getLines() { | ||
return Collections.unmodifiableList(this.lines); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package domain; | ||
|
||
public class Player { | ||
|
||
private final PlayerName playerName; | ||
|
||
public Player(final String playerName) { | ||
this.playerName = new PlayerName(playerName); | ||
} | ||
|
||
public String getName() { | ||
return this.playerName.getName(); | ||
} | ||
|
||
public int getLengthOfPlayerName() { | ||
return this.playerName.getLengthOfName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package domain; | ||
|
||
public class PlayerName { | ||
|
||
private static final int MINIMUM_LENGTH_OF_NAME = 1; | ||
private static final int MAXIMUM_LENGTH_OF_NAME = 5; | ||
|
||
private final String name; | ||
|
||
public PlayerName(final String name) { | ||
validateLengthOfName(name); | ||
this.name = name; | ||
} | ||
|
||
private void validateLengthOfName(final String name) { | ||
if (isNotPermittedLengthOfName(name)) { | ||
throw new IllegalArgumentException("이름의 길이는 최소 1자 이상, 5자 이하입니다."); | ||
} | ||
} | ||
|
||
private boolean isNotPermittedLengthOfName(final String name) { | ||
return (name.length() < MINIMUM_LENGTH_OF_NAME) || (name.length() > MAXIMUM_LENGTH_OF_NAME); | ||
} | ||
|
||
public int getLengthOfName() { | ||
return this.name.length(); | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
값객체 분리 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonypark
추가 질문을 어디에 남길지 몰라서 여기에 남깁니다..!
테스트에 대한 질문입니다!
자동차 경주 결과를 출력하는 로직이 있다면, 이를 테스트 하기 위해서 Car 클래스에 move()를 사용해야합니다. 경주 결과는 Cars 클래스에서 결과를 리턴해준다고 가정했을 때,
Cars.경주결과()
를 테스트 하기 위해서 테스트에서car.move()
와 같은 작동을 미리 해줘야합니다.(경주 결과 판단을 위해서) 이런 경우Cars 테스트
가Car 도메인 메서드
를 의존하게 되는데 이런 경우는 어떻게 하면 좋을까요?소니의 생각이 궁금합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 제이 말대로 Cars가 Car를 가지고 있고 Car의 move 메서드를 통해야 경기 결과를 도출할 수 있습니다.
이건 도메인의 의존성 때문에 테스트에서도 동일한 의존성이 생기는것으로 자연스러운 흐름이라 생각합니다.
레이어별로 controller -> service -> domain -> repository 와 같이 의존성을 갖게 되는데 가장 하위의 레이어의 단위 테스트가 잘 작성되어 있어야 합니다. 하위 레이어의 정상 작동이 보장되어야 그것을 사용하는 상위 레이어도 로직의 안정성을 보장할 수 있습니다. 그렇기 때문에 의존성을 어디에 얼마나 두느냐가 중요한 것 같습니다. 따라서 하위 레이어일수록 꼼꼼히 테스트를 작성합니다. 테스트의 중요도와 우선순위도 (repository) -> domain -> service -> controller 순입니다. (repository는 이미 검증된 라이브러리를 사용하기 때문에 잘 테스트하진 않습니다.🙃)