-
Notifications
You must be signed in to change notification settings - Fork 0
숫자 야구 게임 [sjiwon] #1
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
sjiwon
wants to merge
26
commits into
main
Choose a base branch
from
sjiwon
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 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
67acfb9
docs: 기본 기능 및 모델링에 대한 README.md 작성
sjiwon d1eef0e
feat: Baseballs 관련 상수 인터페이스 구현
sjiwon 7077cce
feat: Baseballs 모델 구현 및 예외 케이스 검증
sjiwon bd0fecc
test: Baseballs 테스트 케이스 작성
sjiwon 2da9bf0
feat: Computer 모델 구현 및 테스트 케이스 작성
sjiwon 312f766
feat: User 모델 구현 및 테스트 케이스 작성
sjiwon 55bee8e
feat: 게임 결과 명세를 위한 Result 모델 구현
sjiwon 6ffb501
feat: 게임 결과 도출을 위한 Referee 모델 구현 및 테스트 케이스 작성
sjiwon 1dde87d
feat: 게임 진행 상태 Tracking을 위한 GameStatus 구현 및 테스트 케이스 작성
sjiwon 7a3481e
feat: 게임 재시작 관련 GameProcessDecider 구현 및 테스트 케이스 작성
sjiwon ed74d6e
feat: 사용자 Input을 위한 InputView 구현
sjiwon cb910f1
feat: 콘솔 출력을 위한 OutputView 구현
sjiwon 7150851
feat: 게임 프로세싱을 위한 GameController 및 Application 동작 처리
sjiwon f28211a
test: Controller 테스트 케이스 추가
sjiwon 7f0707b
refactor: 사용자 숫자 Input시 Baseballs 수만큼 입력했는지 검증 추가
sjiwon b0dabea
refactor: 사용자 Input에 대한 Length 검증 -> 공백 존재 검증 케이스로 수정
sjiwon ba99c7e
refactor: SPACE -> SEPARATOR 네이밍 수정
sjiwon 36107ff
fix: 컴퓨터 Baseballs 랜덤 생성 관련 not equal -> less 조건으로 수정
sjiwon 10961ce
test: Computer Baseballs 랜덤 생성 관련 테스트 케이스 추가
sjiwon e619cf8
refactor: readUserBaseballInput 접근제어자 public -> private
sjiwon 95f69e0
refactor: Computer baseballs 생성 간 내부 로직 메소드화
sjiwon 0e47d89
refactor: Referee strikeCount 계산 로직 간 filter comparing method 분리
sjiwon d71a429
refactor: ExceptionConstants class -> interface
sjiwon 56cf0e5
refactor: 사용자 Input I/O간 검증 순서 수정
sjiwon 991a5d9
refactor: hasSpace 메소드 위치 수정
sjiwon bdb2346
fix: UserTest간 new Baseball -> new User로 수정
sjiwon 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
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,51 @@ | ||
| package baseball.model; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static baseball.utils.BaseballConstants.*; | ||
| import static baseball.utils.ExceptionConstants.BaseballException.*; | ||
|
|
||
| public class Baseballs { | ||
| private final List<Integer> baseballs; | ||
|
|
||
| public Baseballs(final List<Integer> baseballs) { | ||
| validateEachBaseballElementIsInRange(baseballs); | ||
| validateTotalBaseballSize(baseballs); | ||
| validateBaseballHasDuplicateNumber(baseballs); | ||
| this.baseballs = baseballs; | ||
| } | ||
|
|
||
| private void validateEachBaseballElementIsInRange(final List<Integer> baseballs) { | ||
| if (hasOutOfRange(baseballs)) { | ||
| throw new IllegalArgumentException(BASEBALL_IS_NOT_IN_RANGE.message); | ||
| } | ||
| } | ||
|
|
||
| private boolean hasOutOfRange(final List<Integer> baseballs) { | ||
| return baseballs.stream() | ||
| .anyMatch(baseball -> baseball < MIN_BASEBALL || baseball > MAX_BASEBALL); | ||
| } | ||
|
|
||
| private void validateTotalBaseballSize(final List<Integer> baseballs) { | ||
| if (baseballs.size() != BASEBALL_SIZE) { | ||
| throw new IllegalArgumentException(BASEBALL_SIZE_IS_NOT_FULFILL.message); | ||
| } | ||
| } | ||
|
|
||
| private void validateBaseballHasDuplicateNumber(final List<Integer> baseballs) { | ||
| if (hasDuplicateNumber(baseballs)) { | ||
| throw new IllegalArgumentException(BASEBALL_MUST_BE_UNIQUE.message); | ||
| } | ||
| } | ||
|
|
||
| private boolean hasDuplicateNumber(final List<Integer> baseballs) { | ||
| return baseballs.stream() | ||
| .distinct() | ||
| .count() != BASEBALL_SIZE; | ||
| } | ||
|
|
||
| public List<Integer> getBaseballs() { | ||
| return Collections.unmodifiableList(baseballs); | ||
| } | ||
| } | ||
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,16 @@ | ||
| package baseball.utils; | ||
|
|
||
| public class ExceptionConstants { | ||
| public enum BaseballException { | ||
| BASEBALL_IS_NOT_IN_RANGE("숫자는 1..9 범위만 허용합니다."), | ||
| BASEBALL_SIZE_IS_NOT_FULFILL("숫자 3개를 입력해주세요."), | ||
| BASEBALL_MUST_BE_UNIQUE("중복된 숫자는 허용하지 않습니다."), | ||
| ; | ||
|
|
||
| public final String message; | ||
|
|
||
| BaseballException(final String message) { | ||
| this.message = message; | ||
| } | ||
| } | ||
| } |
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.
Collections.unmodifiableList는 Read-only라도 원본 컬렉션의 불변성을 보장하지 않는다고 합니다. CopyOf가 아닌 unmodifiableList를 사용하신 이유가 있을까요?
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.
unmodifiableList를 사용하는거는 원본 객체에 대해서 immutable을 보장하지는 않는데 구조상 Baseballs의 원본 객체를 외부에서 접근할 수 없고 외부에서 얻는
List<Integer> baseballs는 immutable이기 때문에 unmodifiableList를 써도 상관없다고 생각했습니다.