forked from woowacourse/java-ladder
-
Notifications
You must be signed in to change notification settings - Fork 12
[사다리 타기] 김예은 미션 제출합니다. #2
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
yeeun0702
wants to merge
29
commits into
gdgoc-skhu-missions:main
Choose a base branch
from
yeeun0702:main
base: main
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
29 commits
Select commit
Hold shift + click to select a range
edc31fc
docs : README 기능구현 목록 작성
yeeun0702 a454554
feat: InputView, ResultView 구현
yeeun0702 b367140
test: 사람 이름 5글자 이상 예외 처리
sojeong0202 88b6b2b
feat: 사람 이름 5글자 이상 예외 처리 구현
sojeong0202 a49921e
test: 사람 이름 예외 처리 테스트 구현
sojeong0202 6afc0f5
feat: 사람 이름 예외 처리 구현
sojeong0202 0dd15bc
feat: 사다리 높이 예외 처리 테스트 구현
yeeun0702 c393e56
feat: 사다리 높이 예외 처리 구현
yeeun0702 065ab77
feat: Person, LadderMaker 예외처리 적용
yeeun0702 d48d812
test: PersonList 테스트 구현
sojeong0202 2b1b138
feat: PersonList 구현
sojeong0202 b5a1dde
test: 사다리 가로라인에서 True가 겹치면 재조정하는 메소드 테스트코드 구현
yeeun0702 9ec9c84
feat: Line 구현
yeeun0702 f064504
feat: Line 구현
yeeun0702 df1619c
test: 입력 받은 이름 재가공 메소드 테스트 구현
sojeong0202 6b7e70d
feat: 입력 받은 이름 재가공 하는 메소드 구현
sojeong0202 e48df59
feat: 정해진 조건대로 사람 이름출력
yeeun0702 5a2720c
feat: Controller 1차 구현
yeeun0702 5326a52
feat: 매개변수로 입력받은 불리언 리스트에 따라 사다리 출력 메소드 구현
sojeong0202 4b112ad
feat: controller 구현 완료
sojeong0202 314556b
style: 코드 포맷 변경
yeeun0702 2f6fbc8
refactor: PersonList를 분리하여 manipulationPeople과 PersonList를 일급 컬렉션으로 만듬
yeeun0702 59d40d4
refactor: 일급 컬렉션 적용 수정
yeeun0702 5ad3bcb
refactor: Line 클래스 분리
sojeong0202 d638722
style: 코드 컨벤션 적용
sojeong0202 6344529
refactor: LadderTest asserThatThrownBy() 사용하여 변경
yeeun0702 7c2631b
refactor: 들여쓰기가 2 이상인 메소드 분리
yeeun0702 af55f04
refactor: 일급컬렉션 이름 변경
yeeun0702 4751865
MVC 패턴에 맞추어 수정
yeeun0702 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,55 @@ | ||
| ## 기능 구현 목록 | ||
|
|
||
| ### Model | ||
| - [x] 사다리 라인(`|-----|`) | ||
| - [x] `true` 가로 작대기 있음 | ||
| - [x] `false` 가로 작대기 없음 | ||
| - [x] 사다리 maker | ||
| - [x] Boolean을 한 줄 랜덤하게 생성 | ||
| - [x] 랜덤 생성한 Boolean line을 가로라인이 이웃끼리 겹치지 않도록 조정 | ||
| - [x] 사다리 높이 예외처리(0을 제외한 숫자만 가능) | ||
| - [x] 사람 | ||
| - [x] 입력조건 예외처리 | ||
| - [x] 이름 리스트를 형식에 맞게 공백 넣어주기 | ||
|
|
||
| ### View | ||
| #### 입력 조건 | ||
| - [x] 사람 이름 입력하기 | ||
| - [x] 최대 5글자 (사람 이름이 5글자 이하라면 공백문자로 채워줘야 함) | ||
| - [x] 쉼표 기준으로 입력받기 | ||
| - [x] 첫 번째 사람인 경우에, 이름이 5글자 이하여도 여백을 공백문자로 채우지 않음 | ||
| - [x] 사다리 높이 입력받기 | ||
| - [x] 숫자만 입력받기 (공백 or 문자가 입력될 경우 예외처리) | ||
|
|
||
| #### 출력 조건 | ||
| - [x] 이름이 5글자일 경우, 이름의 끝 글자를 기준으로 입력 받은 높이만큼 사다리의 세로 라인 출력 | ||
| - [x] 이름이 5글자 이하인 경우, 이름의 끝 글자 + 공백문자를 기준으로 입력 받은 높이만큼 사다리의 세로 라인 출력 | ||
| - [x] 사다리가 정상적으로 작동하려면 가로 라인이 겹치지 않게 하기(ex.`|-----|-----|`) | ||
| - [x] 사다리 라인(`|-----|`) | ||
| - [x] `true` -> `-----|` | ||
| - [x] `false` -> ` |` | ||
|
|
||
| ### Controller | ||
| - [x] 사다리 타리 진행 | ||
|
|
||
| --- | ||
| # 요구사항 | ||
| 사다리 타기 미션 저장소 | ||
| - 사다리 게임에 참여하는 사람의 이름을 최대 5글자까지 부여할 수 있다. 사다리를 출력할 때 사람 이름도 같이 출력한다. | ||
| - 사람 이름은 쉼표(,)를 기준으로 구분한다. | ||
| - 사람 이름을 5자 기준으로 출력하기 때문에 사다리 폭도 넓어져야 한다. | ||
| - 사다리 타기가 정상적으로 동작하려면 라인이 겹치지 않도록 해야 한다. | ||
| - `|-----|-----|` 모양과 같이 가로 라인이 겹치는 경우 어느 방향으로 이동할지 결정할 수 없다. | ||
|
|
||
| ### 추가된 요구 사항 | ||
| - 모든 기능을 TDD로 구현해 단위 테스트가 존재해야 한다. 단, UI(System.out, System.in) 로직은 제외 | ||
| - 핵심 로직을 구현하는 코드와 UI를 담당하는 로직을 구분한다. | ||
| - UI 로직을 InputView, ResultView와 같은 클래스를 추가해 분리한다. | ||
| - 함수(또는 메서드)의 길이가 10라인을 넘어가지 않도록 구현한다. | ||
| - 함수(또는 메서드)가 한 가지 일만 하도록 최대한 작게 만들어라. | ||
| - 배열 대신 컬렉션을 사용한다. | ||
| - Java Enum을 적용한다. | ||
| - 모든 원시 값과 문자열을 포장한다 | ||
| - 줄여 쓰지 않는다(축약 금지). | ||
| - 일급 컬렉션을 쓴다. | ||
| - |
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 ladder; | ||
|
|
||
| import ladder.controller.LadderController; | ||
| import ladder.view.InputView; | ||
| import ladder.view.ResultView; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| LadderController ladderController = new LadderController(new InputView(), new ResultView()); | ||
| ladderController.start(); | ||
| } | ||
| } |
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 ladder.controller; | ||
|
|
||
| import java.util.List; | ||
| import ladder.model.LadderMaker; | ||
| import ladder.model.Persons; | ||
| import ladder.view.InputView; | ||
| import ladder.view.NameManipulateView; | ||
| import ladder.view.ResultView; | ||
|
|
||
| public class LadderController { | ||
|
|
||
| private final ResultView resultView; | ||
| private final InputView inputView; | ||
| private LadderMaker ladderMaker; | ||
| private List<String> manipulatedPeopleNames; | ||
|
|
||
| public LadderController(InputView inputview, ResultView resultView) { | ||
| this.inputView = inputview; | ||
| this.resultView = resultView; | ||
| } | ||
|
|
||
| public void start() { | ||
| resultView.startMessage(); | ||
|
|
||
| Persons persons = new Persons(inputView.inputName()); | ||
| NameManipulateView nameManipulateView = new NameManipulateView(); | ||
| manipulatedPeopleNames = nameManipulateView.manipulateNames(persons.getPeople()); | ||
|
|
||
| resultView.ladderHeightMessage(); | ||
| this.ladderMaker = new LadderMaker(inputView.inputLadderHeight()); | ||
|
|
||
| resultView.resultMessage(); | ||
| resultView.printPeople(manipulatedPeopleNames); | ||
|
|
||
| for (int i = 0; i < ladderMaker.getLadderHeight(); i++) { | ||
| resultView.printLine(getFirstManipulationName(), getPeopleSize()); | ||
| } | ||
| } | ||
|
|
||
| private List<Boolean> getPeopleSize() { | ||
| return ladderMaker.makeLadder(manipulatedPeopleNames.size()); | ||
| } | ||
|
|
||
| private String getFirstManipulationName() { | ||
| return manipulatedPeopleNames.get(0); | ||
| } | ||
| } |
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 ladder.model; | ||
|
|
||
| import java.util.List; | ||
| import ladder.util.validator.LadderValidator; | ||
|
|
||
| public class LadderMaker { | ||
|
|
||
| private int ladderHeight; | ||
|
|
||
| public LadderMaker(String ladderHeight) { | ||
| LadderValidator.checkEmpty(ladderHeight); | ||
| LadderValidator.checkLadderNumberStandard(ladderHeight); | ||
|
|
||
| this.ladderHeight = Integer.parseInt(ladderHeight); | ||
| } | ||
|
|
||
| public int getLadderHeight() { | ||
| return ladderHeight; | ||
| } | ||
|
|
||
| public List<Boolean> makeLadder(int personCount) { | ||
| RandomBoolean randomBoolean = new RandomBoolean(); | ||
| Line lines = new Line(randomBoolean.createRandomColumn(personCount)); | ||
| return lines.getPoints(); | ||
| } | ||
| } | ||
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 ladder.model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Line { | ||
|
|
||
| private RandomBoolean randomBoolean = new RandomBoolean(); | ||
|
|
||
| private List<Boolean> points; | ||
|
|
||
| public Line(List<Boolean> randomColumn) { | ||
| this.points = randomColumn; | ||
| resetConsecutiveDuplicates(); | ||
| } | ||
|
|
||
| public List<Boolean> getPoints() { | ||
| return points; | ||
| } | ||
|
|
||
| private void resetConsecutiveDuplicates() { | ||
| if (points.isEmpty()) return; | ||
| boolean previousColumn = false; | ||
| for (int i = 0; i < points.size(); i++) { | ||
| points.set(i, updateColumnBasedOnPrevious(i, previousColumn)); | ||
| previousColumn = points.get(i); | ||
| } | ||
| } | ||
|
|
||
| private boolean updateColumnBasedOnPrevious(int index, boolean previousColumn) { | ||
| boolean currentColumn = points.get(index); | ||
| if (previousColumn == currentColumn) { | ||
| return false; | ||
| } | ||
| return currentColumn; | ||
| } | ||
| } |
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,44 @@ | ||
| //package ladder.model; | ||
| // | ||
| //import java.util.ArrayList; | ||
| //import java.util.List; | ||
| // | ||
| //public class ManipulationPeople { | ||
| // | ||
| // private static final int BLOCK_DIGIT = 6; | ||
| // private static final int MAX_NAME_DIGIT = 5; | ||
| // private final List<String> manipulationPeopleNames = new ArrayList<>(); | ||
| // | ||
| // public ManipulationPeople(List<Person> personList) { | ||
| // manipulateNames(personList); | ||
| // } | ||
| // | ||
| // public List<String> getManipulationPeopleNames() { | ||
| // return manipulationPeopleNames; | ||
| // } | ||
| // | ||
| // private void manipulateNames(List<Person> personList) { | ||
| // for (Person person : personList) { | ||
| // manipulationPeopleNames.add(manipulateNameBlank(person.getName())); | ||
| // } | ||
| // } | ||
| // | ||
| // private String manipulateNameBlank(String name) { | ||
| // int blankNumber = BLOCK_DIGIT - name.length(); | ||
| // StringBuilder manipultionName = new StringBuilder(); | ||
| // | ||
| // if (name.length() == MAX_NAME_DIGIT) { | ||
| // manipultionName.append(" "); | ||
| // } | ||
| // | ||
| // for (int i = 0; i < blankNumber - 1; i++) { | ||
| // manipultionName.append(" "); | ||
| // } | ||
| // manipultionName.append(name); | ||
| // | ||
| // if (name.length() != MAX_NAME_DIGIT) { | ||
| // manipultionName.append(" "); | ||
| // } | ||
| // return manipultionName.toString(); | ||
| // } | ||
| //} |
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,19 @@ | ||
| package ladder.model; | ||
|
|
||
| import ladder.util.validator.PersonValidator; | ||
|
|
||
| public class Person { | ||
|
|
||
| private String name; | ||
|
|
||
| public Person(String name) { | ||
| PersonValidator.checkEmpty(name); | ||
| PersonValidator.checkOverRange(name); | ||
| PersonValidator.checkSpace(name); | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
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,27 @@ | ||
| package ladder.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import ladder.util.validator.PersonValidator; | ||
|
|
||
| public class Persons { | ||
|
|
||
| private List<Person> people = new ArrayList<>(); | ||
|
|
||
| public Persons(String nameList) { | ||
| PersonValidator.checkDuplicate(nameList); | ||
| personNameInput(nameList); | ||
| } | ||
|
|
||
| public List<Person> getPeople(){ | ||
| return Collections.unmodifiableList(people); | ||
| } | ||
|
|
||
| private void personNameInput(String nameList) { | ||
| for (String personName : Arrays.asList(nameList.split(","))) { | ||
| people.add(new Person(personName)); | ||
| } | ||
| } | ||
| } |
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,20 @@ | ||
| package ladder.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
|
|
||
| public class RandomBoolean { | ||
| public List<Boolean> createRandomColumn(int personCount) { | ||
| List<Boolean> columns = new ArrayList<>(); | ||
| for (int i = 0; i < personCount - 1; i++) { | ||
| columns.add(getRandomBoolean()); | ||
| } | ||
| return columns; | ||
| } | ||
|
|
||
| private boolean getRandomBoolean() { | ||
| Random random = new Random(); | ||
| return random.nextBoolean(); | ||
| } | ||
| } |
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 ladder.util.validator; | ||
|
|
||
| import ladder.view.ErrorMessageView; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| public class LadderValidator { | ||
|
|
||
| public static void checkEmpty(String input) { | ||
| if (input == null) { | ||
| ErrorMessageView.printErrorMessage(ErrorMessageView.ErrorMessage.INPUT_STRING_NOT_NULL); | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_STRING_NOT_NULL.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static void checkLadderNumberStandard(String input) { | ||
| if (!isRightLadderNumber(input)) { | ||
| ErrorMessageView.printErrorMessage(ErrorMessageView.ErrorMessage.INPUT_LADDER_NUMBER); | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_LADDER_NUMBER.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isRightLadderNumber(String input) { | ||
| return Pattern.matches("^[1-9]\\d*$", input); | ||
| } | ||
| } |
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,59 @@ | ||
| package ladder.util.validator; | ||
|
|
||
| import ladder.view.ErrorMessageView; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class PersonValidator { | ||
|
|
||
| private static final int MAX_DIGIT_PERSON_NAME = 5; | ||
| private static final int MIN_DIGIT_PERSON_NAME = 1; | ||
|
|
||
| public static void checkOverRange(String input) { | ||
| if (isOverRange(input) || isUnderRange(input)) { | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_PERSON_NAME_IS_INCORRECT.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static void checkSpace(String input) { | ||
| if (isSpace(input)) { | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_STRING_BLANK.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static void checkEmpty(String input) { | ||
| if (input == null) { | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_STRING_NOT_NULL.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static void checkDuplicate(String input) { | ||
| if (hasDuplicatePersonName(input)) { | ||
| throw new IllegalArgumentException(ErrorMessageView.ErrorMessage.INPUT_STRING_DUPLICATE.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private static boolean isOverRange(String input) { | ||
| return MAX_DIGIT_PERSON_NAME < input.length(); | ||
| } | ||
|
|
||
| private static boolean isUnderRange(String input) { | ||
| return MIN_DIGIT_PERSON_NAME > input.length(); | ||
| } | ||
|
|
||
| private static boolean isSpace(String input) { | ||
| return Pattern.matches("^\\s+$", input); | ||
| } | ||
|
|
||
| private static boolean hasDuplicatePersonName(String input) { | ||
| List<String> allPersonNames = new ArrayList<>(Arrays.asList(input.split(","))); | ||
| Set<String> set = new HashSet<>(allPersonNames); | ||
|
|
||
| return allPersonNames.size() != set.size(); | ||
| } | ||
| } |
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.
이 클래스의 이름이
LadderMaker였어야 할까요?List<Line>을 가진Ladder나Lines였다면 어땠을까요?사람 수만큼 여러 라인들을 생성하고 조립하여 하나의 사다리를 만드는 일급 컬렉션으로 볼 수 있지 않을까요?