Open
Conversation
added 23 commits
January 15, 2023 16:41
build.gradle에 코드 추가
경주할 자동차 이름을 입력받고, 시도할 횟수를 입력받습니다. 자동차를 전진시킵니다. 자동차 경주 게임을 완료한 후 누가 우승했는지를 출력합니다.
camp.nextstep.edu.missionutils.Console의 readLine()을 사용해서 값 읽어들였습니다.
ready() 메서드를 통해 경주 시작 전 준비하는 일을 합니다. run() 메서드를 통해 자동차 경주 게임을 진행합니다. announceWinner() 메서드를 통해 자동차 경주 게임의 승자를 발표합니다.
쉼표(,)로 나누기 전에는 null, empty, duplicate를 체크했습니다. 쉼표로 나눈 후 각각의 자동차 이름에 대해 null,empty,length를 체크했습니다. isBlank 메서드가 java11버전부터 사용할 수 있기 때문에 carName.isEmpty() || carName.trim().isEmpty() 를 이용해 공백 처리를 구현했습니다.
@ParameterizedTest를 이용해서 테스트에 여러 다른 매개변수를 대입해가며 반복 실행했습니다.
자동차 이름의 유효성을 검증하는 코드이기 때문에 NameValidatorTest에 적합하다고 판단했습니다.
정상적인 경우와, 실패했을 경우를 나눠 테스트했습니다.
AttemptNumberValidator에서 숫자가 1 미만일 때와 숫자가 아닌 입력에 대해 예외처리를 해주었습니다.
ERROR 메시지를 입출력 요구사항에 나와있는 것과 같이 변경했습니다.
사용자가 숫자가 아닌 문자를 입력했을 때나, 1회 미만의 숫자를 입력했을 때 IllegalArgumentException을 발생시키도록 구현했습니다.
시도 횟수가 정상적으로 입력되었을 때의 테스트 결과를 추가했습니다.
유효성 검사 시점을 자동차 이름을 생성할 때가 아닌 Cars 일급 콜렉션에 추가할 때 로 변경하였습니다. NameGenerator 클래스에서 검증 로직을 진행할 필요가 없다고 생각했습니다.
일급 컬렉션에 findWinners() 메서드와 findMaxPosition() 메서드를 구현해서 우승자와 가장 멀리 간 자동차를 찾도록 했습니다.
전진하는 조건은 0에서 9 사이에서 무작위 값을 구한 후 무작위 값이 4 이상일 경우 자동차를 전진시킵니다.
우승자가 여러 명일 경우 String.join을 사용해서 구분했습니다.
0에서 9 사이의 무작위 값을 구한 후 무작위 값이 4 이상이면 자동차를 이동시킵니다.
Arguments.arguments 메서드가 내부적으로 Arguments.of 메서드를 호출하는 구조여서 Arguments.of 메서드로 바꿔주었습니다.
run 메서드는 자동차 경주를 나타내는 일만 하도록 실행 결과 라는 문구를 출력하는 코드 를 분리하여 메서드로 추출했습니다.
이전의 코드는 Integer -> int 로 변환하는 과정에서 언박싱 비용이 들어갑니다. 그러나 기본형 특화 스트림인 IntStream을 사용하면 박싱 비용을 피할 수 있습니다.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.