-
Notifications
You must be signed in to change notification settings - Fork 450
[빙봉] 자동차 경주 미션 제출합니다. #109
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
Conversation
- 커스텀 구분자 방식 변경("//#\n1#2#3" -> "//#//woowacourse#1#2#3")
- Car생성자에 이름(String) 매개변수 추가
- refactor: 메서드명 변경 printResult -> printNotice
- 입력 round 값 RacingCar 인스턴스 변수화 - 메서드 구조, 네이밍 수정 - 변경에 따른 테스트 코드 수정
jeonghoon1107
left a comment
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.
안녕하세요 빙봉!
구현 잘 하셨네요 💯
몇가지 피드백을 남겼으니 확인해주세요 :)
| } | ||
|
|
||
| private static String validateName(String name) { | ||
| name = name.trim(); |
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.
name = null;
name.trim()을 하는 경우에는 어떻게 되나요?
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.
validateNullOrEmpty(name); 을 name.trim()하기 전에 하도록 수정했습니다!
|
|
||
| @DisplayName("랜덤 생성된 값이 4이상일 때 이동 테스트") | ||
| @ParameterizedTest | ||
| @CsvSource(value = {"1,false", "2,false", "3,false", "4,true", "5,true", "6,true", "7,true", "8,true", "9,true"}) |
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.
테스트 코드 역시 리팩토링의 대상입니다. 너무 많은 케이스를 테스트할 필요는 없어보여요.
경계값을 기반으로 테스트하도록 변경해보면 좋을 것 같아요.
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.
처음 리펙토링을 했을 때 0, 3, 4, 9 순으로 리펙토링을 했습니다. 그러나 다시 리펙토링하면서 RandomNumber 객체에게 메세지를 보내도록 하여 아래와 같은 테스트 코드로 수정했습니다!
if(randomNumber.getRandomNumber() >= 4) {
assertThat(position.getDistance() == 1).isTrue();
}RandomNumber 객체 - randomNumber를 validate해주기 위해 validateRandomNumber() 메서드 추가 - 객체에게 움직일 수 있냐는 메세지를 보내기 위해 isMovable() 메서드 추가
jeonghoon1107
left a comment
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.
안녕하세요 빙봉!
아쉬운 점이 있어서 피드백 남겼습니다!
확인해주세요 :)
| return randomNumber >= RANDOM_MIN_LIMIT_NUMBER && randomNumber < RANDOM_MAX_LIMIT_NUMBER; | ||
| } | ||
|
|
||
| public static boolean isMovable() { |
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.
움직임에 대한 판단은 RandomNumber가 하는 것이 맞나요?
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.
isMovable() 메서드는 Car의 Position에게 물어보는 것이 맞다고 판단되어 수정했습니다!
|
|
||
| public RandomNumber() { | ||
| int randomNumber = generateRandom(); | ||
| if(validateRandomNumber(randomNumber)){ |
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.
유효하지 않으면 어떻게 되나요?
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.
Random 클래스에서 생성해주는 범위가 이미 있기 때문에 굳이 validate 해주지 않아도 될 것 같다고 판단하여 validate 메서드를 삭제했습니다!
|
|
||
| import java.util.Random; | ||
|
|
||
| public class RandomNumber { |
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.
상태값을 가질 필요가 없는 것 같은데 매번 인스턴스를 생성할 필요가 있을까요?
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.
말씀대로 상태값을 가질 필요가 없을 것 같아 RandomNumber의 속성을 지우고 랜덤 번호를 생성해주는 메서드만 만들어 호출하도록 했습니다!
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.
상태 값을 갖지 않는 클래스로 변경되었는데 RandomNumber라는 클래스 이름도 명시적으로 변경되면 좋을 것 같아요!
하나의 랜덤한 숫자같은 의미처럼 보여요!
| public class Cars { | ||
|
|
||
| private static final String EMPTY_STRING = ""; | ||
| private static final CarFactory carFactory = new CarFactory(); |
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.
CarFactory가 상태값을 가지고 있나요?
상태값을 갖는 것과 갖지 않는 것에 대해 구분할 필요가 있어보여요!
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.
CarFactory가 상태값을 가지지 않고 있고 팩토리 패턴을 사용한 것도 아니며 메소드를 뺀 것에 불과한 것 같아 삭제했습니다!
|
|
||
| public class CarTest { | ||
|
|
||
| @DisplayName("랜덤 생성된 값이 4이상일 때 이동 테스트") |
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.
4 이하일 때의 케이스를 추가해야할 것 같아요.
또한, 해당 테스트를 보면 car에 대한 테스트가 아니고 position에 대한 테스트 같네요 :)
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.
move()에 대해서 코드를 고치고 테스트케이스를 수정했습니다!
| } | ||
| } | ||
|
|
||
| public String getResult() { |
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.
우승자를 관리하는 클래스를 따로 분리하면 어떨까요?
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.
Winners 라는 클래스를 만들어 따로 분리했습니다! 다만 제 Winners 클래스에 보면 매개변수로 모두 cars를 받기때문에 상태값이 없는 클래스가 되었는데 이렇게 메소드만으로 정의한 클래스를 클래스 분리로 생각해도 좋을지 여쭙고 싶습니다! 메소드가 우승자에 관련되어 있다는 것만으로 우승자라는 클래스로 분리하는 것이 괜찮은 생각인지 궁금합니다!
public class Winners {
public static List<Car> findWinner(List<Car> cars) {
int maxPosition = 0;
for(Car car : cars) {
maxPosition = car.getBiggerPosition(maxPosition);
}
return getWinners(cars, maxPosition);
}
private static List<Car> getWinners(List<Car> cars, int maxPosition) {
List<Car> winners = new ArrayList<>();
for(Car car : cars) {
if(car.isWinner(maxPosition)){
winners.add(car);
}
}
return winners;
}
}…View에 ","를 joining하도록 구현, isNotEmpty() 메서드 삭제
jeonghoon1107
left a comment
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.
안녕하세요 빙봉!
깔끔하네요 👍
아쉬운 점이 있어서 피드백 남겼으니 확인해주세요!
| } | ||
|
|
||
| public void move(int number) { | ||
| if(position.isMovable(number)) { |
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.
position이 움직임을 판단하는 것보다 car가 판단하는 것은 어떨까요?
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.
객체에 역할에 따라 판단해야된다고 생각해 Car 객체에 isMovable() 메서드를 넣도록 했습니다!
| private final List<Car> cars; | ||
|
|
||
| public Cars(String inputNames) { | ||
| String[] names = inputNames.split(DELIMITER); |
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.
메서드로 추출하면 조금 더 깔끔해질 것 같아요!
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.
split과 아래 for문 모두 수정했습니다!
| cars.getCars() | ||
| .add(new Car(new Position(maxPosition), "user5")); | ||
|
|
||
| assertThat(cars.getCars() |
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.
테스트안에 비즈니스 로직에 해당하는 부분이 별도로 구현되어있네요!
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.
CarTest에 이미 isWinner를 테스트하고 있었는데 못 봤던 것 같습니다! 테스트하려는 메소드 자체가 없어서 삭제했습니다. 테스트 안에 비즈니스 로직을 넣지 않도록 염두하겠습니다!
| .stream() | ||
| .filter(car -> car.isWinner(maxPosition)) | ||
| .findFirst() | ||
| .get() |
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.
get이 어떻게 구현되어있는지 보셨나요? get의 사용은 지양하는 것이 좋을 것 같아요.
public T get() { if (value == null) { throw new NoSuchElementException("No value present"); } return value; }
|
|
||
| import java.util.Random; | ||
|
|
||
| public class RandomNumber { |
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.
상태 값을 갖지 않는 클래스로 변경되었는데 RandomNumber라는 클래스 이름도 명시적으로 변경되면 좋을 것 같아요!
하나의 랜덤한 숫자같은 의미처럼 보여요!
jeonghoon1107
left a comment
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.
안녕하세요 빙봉!
깔끔하네요 💯
미션 진행하느라 고생 많으셨습니다 :)
많은 피드백 부탁드립니다! 감사합니다!!