Skip to content
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

4단계 - 자동차 경주(우승자) #6054

Open
wants to merge 6 commits into
base: yeonjiyeon
Choose a base branch
from

Conversation

yeonjiyeon
Copy link

4단계 진행하였습니다.
리뷰 부탁드리겠습니다:)

jinyoungchoi95

This comment was marked as off-topic.

Copy link

@jinyoungchoi95 jinyoungchoi95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 지연님 😄

다음 미션 잘 진행해주셨네요! 몇가지 코멘트 남겨두었으니 확인부탁드려요 :)

궁금하거나 고민이 되는 부분이 있으시다면 언제든 pr 코멘트 또는 dm으로 요청 부탁드립니다.
감사합니다 🙇‍♂️

Comment on lines +17 to +19
private void validateName(String name) {
if (name.length() > MAX_NAME_LENGTH) {
throw new IllegalArgumentException("자동차 이름은 " + MAX_NAME_LENGTH + "자를 초과할 수 없습니다.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자바 표준 예외 사용 👍

Comment on lines +32 to +34
if (randomNumber < 0 || randomNumber > 9) {
throw new IllegalArgumentException("랜덤 값은 0에서 9 사이여야 합니다.");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 코멘트를 이번 단계에서 드리려했는데 이미 만들어주셨군요 😄

0과 9는 상수로 분리되어도 좋을 것 같아요!

@@ -6,17 +6,24 @@

public class Racing {

List<Car> cars = new ArrayList<>();
private final List<Car> cars = new ArrayList<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<Car>를 핵심적으로 다루는 객체가 되면서(움직임, 우승자) Racing보다는 "자동차들"을 관리한다는 이름을 잘 전달해주는 네이밍으로 변경해보면 어떨까요?

Comment on lines +19 to +21
private static String[] StringToArray(String carNamesRaw) {
return carNamesRaw.split(",");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

","로 분리되어 들어온다는 것은 화면단의 요구사항이므로 domain보다는 view에서 처리되면 좋을 것 같아요 😄

@@ -30,5 +37,28 @@ public void simulateRace() {
}
}

public List<String> getMaxPosition() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기능상 네이밍이 가장 높은 위치를 가져온다라기보다는 우승자를 찾는다의 네이밍에 맞게 변경되어야겠네요 :)

Comment on lines +42 to +45
int maxPosition = 0;
for (Car car : cars) {
maxPosition = findMaxPosition(maxPosition, car);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사실상 이 부분이 findMaxPosition에 가깝고, 기존의 findMaxPositioncompareMaxPosition과 같은 비교하여 더 높은 것을 가져온다에 가까워보이네요!

결과적으로는

int maxPosition = findMaxPosition(...);

으로 메서드를 사용할 수 있도록 구성해보면 어떨까요?

Comment on lines +46 to +49
for (Car car : cars) {
addMaxPositionCar(maxPositionCars, maxPosition, car);
}
return maxPositionCars;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분도 하나의 메서드로써 return calcualteMaxPositionCars(...);와 같이 기능 제공을 하면 메서드를 가독성있게 분리해볼 수 있겠네요 😄


}

@Test
void 제일_높은_position_가진_자동차_구하기() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -20,5 +21,26 @@ public class CarTest {
car.driveOrStop(4);
assertThat(car.getPosition()).isEqualTo(1);
}

@Test
void 랜덤값_마이너스() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트는 결국 랜덤값이 0미만인 경우 예외를 던진다라는 기능이기 때문에 어떤 결과를 만들어내는지에 대한 의미도 메서드명에 전달되면 어떨까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants