forked from woowacourse/java-ladder
-
Notifications
You must be signed in to change notification settings - Fork 12
[사다리 타기] 김우진 미션 제출합니다. #8
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
Open
woogym
wants to merge
24
commits into
gdgoc-skhu-missions:woogym
Choose a base branch
from
woogym:main
base: woogym
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7bcbdeb
docs: 구현할 기능 목록 추가
inhooo00 52d3e29
feat: 전체적인 코드 구현
inhooo00 06e9f84
[feat] Line 테스트코드 수정
woogym 4b22a97
fix: InputView-readPlayerNames, LadderGameController createPlayersFro…
woogym 4b1d3bb
docs: modified README.md
woogym c041f97
style: EOL code formating
woogym 71237b4
fix: model/Ladder method therefore Controller, OutputView to
woogym 3e02b65
fix: LadderTest.java TEST_GenerateLadder_OPERATION mothod
woogym 6a303fb
fix: modifiy the ladder drawing part to OutputView responsibility
woogym 77be39b
style: delete unused code in Ladder.java
woogym 6277db2
fix: modify PlayerValidator method format
woogym cbb90a0
style: culf validator test class
woogym 7078c7c
feature: getLines method
woogym 01000e6
fix: modify generateLadder method test
woogym 8d78464
fix: modify Height object create test method
woogym 21762be
fix: makeLinewithNotFoothold test method
woogym 5b180c0
fix: makeLineWithFoothold test method
woogym 6672047
fix: Line.java makeLine mehtod
woogym a400f84
fix: overall LineTest test code
woogym be42958
style: modify test method naming
woogym f48250c
feature: LinesTest addLineTest method
woogym a210404
feature: LinesTest convertLinesToBooleanArrayTest method
woogym 44bdede
style: modify overall test code method naming
woogym afef7f0
docs: modify README.md
woogym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,50 @@ | ||
| # 구현할 기능 목록 | ||
|
|
||
| ## 입력 | ||
| - [x] 사용자 이름 입력 | ||
| - [x] 쉼표로 구분 | ||
| - [x] 최대 5글자까지 가능 | ||
| - [x] 사다리 높이 입력 | ||
| - [x] 자연수 | ||
|
|
||
|
|
||
| ## 출력 | ||
| - [x] 실행 결과 | ||
| - [x] 첫번째 줄 : 사람 이름 | ||
| - [x] 그 아래 줄 : 사다리 그리기 | ||
|
|
||
| ## 기능 | ||
| - [x] 사람의 이름을 받고 , 기준으로 나누기. | ||
| - [x] 한 줄에 | 개수를 사람 이름 개수만큼 반환. | ||
| - [x] 랜덤 값 기능 구현 | ||
| - [x] 랜덤에 충족하면 ----- 그리기. | ||
| - [x] 한줄의 |에 ----- 연결선이 동시에 나오지 않게 | ||
| - [x] 테스트 코드 작성 | ||
|
|
||
|
|
||
| ## TDD 객체 명세서 | ||
| - [x] Height | ||
| - [x] 객체 생성 가능 | ||
| - [x] Ladder | ||
| - [x] 객체 생성 가능 | ||
| - [x] 전체적인 줄이 잘 생성되는지 테스트 | ||
| - [x] Line | ||
| - [x] 객체 생성 가능 | ||
| - [x] 예상되는 사다리 라인 문자열 | ||
| - [x] Player | ||
| - [x] 객체 생성 가능 | ||
| - [x] Players | ||
| - [x] 객체 생성 가능 | ||
| - [x] util | ||
| - [x] LadderHeightValidator | ||
| - [x] 정상_입력 | ||
| - [x] 정수가_아닌_입력 | ||
| - [x] 음수_입력 | ||
| - [x] 공백_입력 | ||
| - [x] PlayerNamesValidator | ||
| - [x] 정상_입력 | ||
| - [x] 공백_포함 | ||
| - [x] 공백 | ||
| - [x] 이름_길이_초과 | ||
| - [x] 중복_입력 | ||
| # 1차 리뷰 후 개선 방향 |
This file contains hidden or 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,10 @@ | ||
| import controller.LadderGameController; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) throws IOException { | ||
| LadderGameController ladderGameController = new LadderGameController(); | ||
| ladderGameController.run(); | ||
| } | ||
| } |
This file contains hidden or 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,57 @@ | ||
| package controller; | ||
|
|
||
| import model.Height; | ||
| import model.Ladder; | ||
| import model.Lines; | ||
| import model.Player; | ||
| import model.Players; | ||
| import util.RandomFootholdGenerator; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LadderGameController { | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| public LadderGameController() { | ||
| this.inputView = new InputView(); | ||
| this.outputView = new OutputView(); | ||
| } | ||
|
|
||
| public void run() throws IOException { | ||
| Players players = createPlayersFromInput(); | ||
| List<String> playerNames = extractPlayerNames(players); | ||
| Height height = createHeightFromInput(); | ||
| Lines ladderLines = createLadder(height, players); | ||
|
|
||
| List<List<Boolean>> linesStructure = ladderLines.toBooleanList(); | ||
| outputView.printResultSentence(linesStructure, playerNames); | ||
| } | ||
|
|
||
| private Players createPlayersFromInput() throws IOException { | ||
| String[] playerNamesArray = inputView.readPlayerNames(); | ||
|
|
||
| return new Players(Arrays.asList(playerNamesArray)); | ||
| } | ||
|
|
||
| private List<String> extractPlayerNames(Players players) { | ||
| return players.getPlayers().stream() | ||
| .map(Player::getName) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private Height createHeightFromInput() throws IOException { | ||
| return new Height(inputView.readLadderHeightNumber()); | ||
| } | ||
|
|
||
| private Lines createLadder(Height height, Players players) { | ||
| Ladder ladder = new Ladder(); | ||
|
|
||
| return ladder.generateLadder(height, players.findNumberOfPlayers() - 1); | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| package exception; | ||
|
|
||
| public enum ErrorMessage { | ||
|
|
||
| DUPLICATED_CAR_NAME("참여자 이름이 중복될 수 없습니다."), | ||
| NOT_ALLOW_BLANK("참여자 이름에 공백이 들어갈 수 없습니다."), | ||
| NOT_ALLOW_EMPTY("참여자 입력 값이 비어있을수 없습니다."), | ||
| INVALID_NAME_LENGTH("참여자의 이름은 5자 이하여야합니다."), | ||
| NOT_NUMERIC("시도 횟수 입력은 숫자여야 합니다."), | ||
| ONLY_NATURAL_NUMBER("시도 횟수는 자연수여야합니다"), | ||
| NOT_ALLOW_ZERO("사다리 높이는 0이 될 수 없습니다"); | ||
|
|
||
| private final String message; | ||
|
|
||
| ErrorMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
src/main/java/exception/LadderGameValidationException.java
This file contains hidden or 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,47 @@ | ||
| package exception; | ||
|
|
||
| public class LadderGameValidationException { | ||
|
|
||
| public static class DuplicatedPlayerNameException extends IllegalArgumentException { | ||
| public DuplicatedPlayerNameException() { | ||
| super(ErrorMessage.DUPLICATED_CAR_NAME.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class BlankPlayerNameException extends IllegalArgumentException { | ||
| public BlankPlayerNameException() { | ||
| super(ErrorMessage.NOT_ALLOW_BLANK.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class NotAllowEmptyInputException extends IllegalArgumentException { | ||
| public NotAllowEmptyInputException() { | ||
| super(ErrorMessage.NOT_ALLOW_EMPTY.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class InvalidPlayerNameLengthException extends IllegalArgumentException { | ||
| public InvalidPlayerNameLengthException() { | ||
| super(ErrorMessage.INVALID_NAME_LENGTH.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class NotNumericException extends IllegalArgumentException { | ||
| public NotNumericException() { | ||
| super(ErrorMessage.NOT_NUMERIC.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class NotNaturalNumberException extends IllegalArgumentException { | ||
| public NotNaturalNumberException() { | ||
| super(ErrorMessage.ONLY_NATURAL_NUMBER.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static class NotAllowZeroNumberException extends IllegalArgumentException { | ||
| public NotAllowZeroNumberException() { | ||
| super(ErrorMessage.NOT_ALLOW_ZERO.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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,14 @@ | ||
| package model; | ||
|
|
||
| public class Height { | ||
|
|
||
| private final String height; | ||
|
|
||
| public Height(final String height) { | ||
| this.height = height; | ||
| } | ||
|
|
||
| public String getHeight() { | ||
| return height; | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| package model; | ||
|
|
||
| import util.RandomFootholdGenerator; | ||
|
|
||
| public class Ladder { | ||
| private Lines lines; | ||
|
|
||
| public Ladder() { | ||
| this.lines = new Lines(); | ||
| } | ||
|
|
||
| public Lines generateLadder(Height height, int size) { | ||
| for (int i = 0; i < Integer.parseInt(height.getHeight()); i++) { | ||
| Line line = new Line(new RandomFootholdGenerator(), size); | ||
| line.makeLine(); | ||
| lines.addLine(line); | ||
| } | ||
|
|
||
| return lines; | ||
| } | ||
| } |
This file contains hidden or 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,36 @@ | ||
| package model; | ||
|
|
||
| import util.FootholdGenerator; | ||
|
|
||
| public class Line { | ||
|
|
||
| private static final int INITIAL_INDEX = 0; | ||
| private static final int STEP_SIZE = 2; | ||
|
|
||
| private final boolean[] line; | ||
| private final FootholdGenerator footholdGenerator; | ||
|
|
||
| public Line(FootholdGenerator footholdGenerator, int size) { | ||
| this.line = new boolean[size]; | ||
| this.footholdGenerator = footholdGenerator; | ||
| } | ||
|
|
||
| public void makeLine() { | ||
| for (int i = INITIAL_INDEX; i < line.length; i++) { | ||
| tryToPlaceFootholdAt(i); | ||
| } | ||
| } | ||
|
|
||
| private boolean tryToPlaceFootholdAt(int index) { | ||
| if (!line[index] && footholdGenerator.generate()) { | ||
| line[index] = true; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public boolean[] getLine() { | ||
| return line; | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,38 @@ | ||
| package model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Lines { | ||
|
|
||
| private final List<Line> lines = new ArrayList<>(); | ||
|
|
||
| public void addLine(Line line) { | ||
| lines.add(line); | ||
| } | ||
|
|
||
| public List<List<Boolean>> toBooleanList() { | ||
| return lines.stream() | ||
| .map(this::convertLineToBooleanList) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Line> getLines() { | ||
| return lines; | ||
| } | ||
|
|
||
| private List<Boolean> convertLineToBooleanList(Line line) { | ||
| boolean[] points = line.getLine(); | ||
| return convertArrayToBooleanList(points); | ||
| } | ||
|
|
||
| private List<Boolean> convertArrayToBooleanList(boolean[] points) { | ||
| List<Boolean> booleanList = new ArrayList<>(); | ||
| for (boolean point : points) { | ||
| booleanList.add(point); | ||
| } | ||
| return booleanList; | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,15 @@ | ||
| package model; | ||
|
|
||
| public class Player { | ||
|
|
||
| private final String playerName; | ||
|
|
||
| public Player(String playerName) { | ||
| this.playerName = playerName; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return this.playerName; | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,26 @@ | ||
| package model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Players { | ||
|
|
||
| private final List<Player> players; | ||
|
|
||
| public Players(List<String> playerNames) { | ||
| this.players = makePlayers(playerNames); | ||
| } | ||
|
|
||
| public int findNumberOfPlayers() { | ||
| return this.players.size(); | ||
| } | ||
|
|
||
| public List<Player> getPlayers() { | ||
| return players; | ||
| } | ||
|
|
||
| private List<Player> makePlayers(final List<String> playerNames) { | ||
| return playerNames.stream() | ||
| .map(Player::new) | ||
| .toList(); | ||
| } | ||
| } | ||
|
Comment on lines
+5
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일급 컬렉션 활용 👍 |
||
This file contains hidden or 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,5 @@ | ||
| package util; | ||
|
|
||
| public interface FootholdGenerator { | ||
| boolean generate(); | ||
| } | ||
|
Comment on lines
+3
to
+5
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인터페이스 활용 👍 |
||
This file contains hidden or 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,13 @@ | ||
| package util; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class RandomFootholdGenerator implements FootholdGenerator{ | ||
|
|
||
| private static Random random = new Random(); | ||
|
|
||
| @Override | ||
| public boolean generate() { | ||
| return random.nextBoolean(); | ||
| } | ||
| } |
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.
Custom Exception을 구현하셨네요! Nested Class로 구현하신 특별한 이유가 있으실까요?
IllegalArgumentException으로 충분히 처리 가능한 것 같은데 Custom Exception을 구현한 이유는 무엇인가요?