Skip to content

[자동차 경주] 이상현 미션 제출합니다. #120

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
wants to merge 29 commits into
base: idealhyun
Choose a base branch
from

Conversation

idealHyun
Copy link

자동차 경주 - 초간단 애플리케이션

학습 내용

  • 예외 처리 방법
  • Mock을 통한 랜덤 값 처리

코드 설명

  • 입력을 통해 차 이름과 게임 라운드를 입력 받는다.
    • 차 이름은 CarNameParser를 통해서 쉼표를 구분해서 분리한다.
  • 라운드를 수행하며 차를 전진시킨다.
    • 실행 결과와 관련된 내용은 StringBuilder 에 추가한다.
  • 라운드가 끝나고 가장 멀리나간 자동차의 거리를 반환받고 해당 거리에 있는 자동차들을 우승자로 결정한다.

회고

  • TDD 해보려했는데 잊어버렸다. 추천해주신 강의 꼭 보고 다음 미션에는 적용해보려 노력해야겠다.
  • 단축키나 live template를 최대한 사용하려 노력했다.
  • 랜덤 값을 처리하는 로직에 대해 테스트 코드 작성하는 것이 어려웠다.
  • 아직도 테스트 코드 작성에 있어 미숙한 것 같다.
  • 마지막에 보니 CarRace 생성시에 NumberGenerator 를 주입하는 것이 이상한 것 같다.

idealHyun added 29 commits May 3, 2025 15:18
- util 형태로 생성
- 게임 시작 메소드
- 라운드 만큼 시행
- Car 리스트로부터 가장 큰 distance 값 받아오기
- 가장 큰 distance를 기준으로 같은 값을 가진 Car들을 우승자로 정하기
- 랜덤한 값 테스트를 위한 인터페이스 생성
- 자동차 이름 5자 이하 유효성 검증
- 자동차 이름 공백 유효성 검증
- , 를 기준으로 이름 나누는 기능
@idealHyun idealHyun changed the title [자동차 경주] - 이상현 미션 제출합니다. [자동차 경주] 이상현 미션 제출합니다. May 7, 2025
Copy link

@hong-sile hong-sile left a comment

Choose a reason for hiding this comment

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

첫 번째 제출 수고하셨습니다!

몇몇 부분들에 대해서 코멘트 남겼어요.

주어진 컨벤션 룰과 4단계 내용에 조금 더 집중해보면 좋을 것 같아요.
만약에 주어진 상황에서 출력이 콘솔이 아닌 gui가 된다면? 또는 웹 응답이 된다면? 어디가 바뀌어야 하고 얼만큼 영향을 받을지 생각해보면 더 도움이 될것 같습니다.

리뷰 남긴부분에 대한 답변 부탁드리고 궁금한 부분들 계속 물어봐주세요!

@@ -14,6 +14,8 @@ dependencies {
testImplementation platform('org.assertj:assertj-bom:3.25.1')
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation('org.assertj:assertj-core')
testImplementation('org.mockito:mockito-core:5.11.0')

Choose a reason for hiding this comment

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

오 mockito를 쓰셨군요...

@@ -0,0 +1,5 @@
package domain;

public interface NumberGenerator {

Choose a reason for hiding this comment

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

NumberGenerator라는 Interface를 만들었군요 혹시 이 Interface는 어떻게 쓰이나요?

@ExtendWith(MockitoExtension.class)
public class CarRaceTest {
@Mock
NumberGenerator randomNumberGenerator;

Choose a reason for hiding this comment

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

@mock 어노테이션은 어떤역할을 하나요?

import java.util.Random;

public class RandomNumberGenerator implements NumberGenerator {
private final int MAX_RANDOM_NUMBER = 10;

Choose a reason for hiding this comment

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

위의 값들은 static을 안 썼고, 아래 Random은 static을 썼군요. 어떤 차이가 있나요?

그리고 자바에서 static이 붙고 안붙는게 변수이름에 어떤식으로 적용이 될까요?
(참고 자료 : 구글 자바 네이밍 컨벤션)

}

private void validate(String name) {
if(name.length() > MAX_CAR_NAME_LENGTH ){

Choose a reason for hiding this comment

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

discord에서 이야기했던 것처럼 포맷팅을 한번 해보면 좋을 것 같아요.

xml을 등록하고 reformat code를 하면 알아서 다 바뀐답니당

}
}

private void recordOutput(Car car) {

Choose a reason for hiding this comment

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

요것도 출력과 관련있는 내용인 것 같아요. 만약에, 저희가 gui를 제공하도록 바뀌어야한다고 하면 어디가 영향을 받을까요?

import java.util.Arrays;
import java.util.List;

public class CarNameParser {

Choose a reason for hiding this comment

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

CarNameparser는 어떤 의도로 만들었고, 지금상황에서 필요할까요?

import java.util.List;

public class CarNameParser {
private final String DELIMITER=",";

Choose a reason for hiding this comment

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

이 값이 불변이라면 다른 방식으로 표현해보면 어떨까요??

static을 붙인 변수와 붙이지 않은 변수는 실제로 어떤 차이가 있나요?

@DisplayName("게임 라운드 정수 입력 테스트: 예외 발생")
void invalidInputGameRounds(String input) {
// Given
System.setIn(new ByteArrayInputStream((input + "\n").getBytes()));

Choose a reason for hiding this comment

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

InputViewTest를 해보셨군요. 해보니까 view를 테스트하는건 어떘나요?


@Nested
@DisplayName("자동차 생성 - 이름 테스트")
class InvalidCarNameTest {

Choose a reason for hiding this comment

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

Nested를 잘 나눠주신것 좋습니다.

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