-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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단계 - 자동차 경주(우승자) #6057
base: yooncheolkim
Are you sure you want to change the base?
4단계 - 자동차 경주(우승자) #6057
Conversation
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.
조금 더 개선한 뒤 다시 요청부탁드리겠습니다 :)
System.out.print(getCurrentPositionDash()); | ||
System.out.print("\n"); | ||
} | ||
|
||
public String getCurrentPositionDash() { |
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.
이 부분도 view와 강하게 관계가 있는 코드로 보이네요!
여러가지 view에서 서로다른 표현방식을 지원해야할때 이러한 메서드가 유용할까요? 🤔
if (name.length() > 5) { | ||
throw new RuntimeException("name은 5자를 초과할 수 없습니다. name :" + name); | ||
} | ||
|
||
this.name = name; |
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 List<Car> getWinner() { | ||
List<Car> result = new ArrayList<>(); | ||
|
||
int max = 0; | ||
for (Car car : carList) { | ||
car.print(); | ||
if (max < car.getCurrentPosition()) { | ||
max = car.getCurrentPosition(); | ||
result.clear(); | ||
result.add(car); | ||
} else if (max == car.getCurrentPosition()) { | ||
result.add(car); | ||
} | ||
} | ||
System.out.print("\n"); | ||
|
||
return result; |
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.
이러한 역할을 담당해줄 별도의 객체를 설계해보면 어떨까요?
일급컬렉션에 대해 알아보시면 좋을것 같습니다. :)
while(racing.isRemainTry()){ | ||
racing.move(); | ||
} | ||
|
||
List<Car> winnerList = racing.getWinner(); | ||
int winnerPosition = winnerList.get(0).getCurrentPosition(); | ||
|
||
for(Car car : racing.getCarList()){ | ||
assertThat(car.getCurrentPosition()).isLessThanOrEqualTo(winnerPosition); | ||
} |
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.
테스트 코드에서 while과 for-loop는 제거해주세요~!
테스트 코드는 한번에 읽기 좋아야 합니다!
만약 이러한 로직이 없이 테스트를 수행해야 한다면 객체의 설계가 잘못되었거나 새로운 객체가 필요하지 않은지 고민해보시면 좋을것 같습니다. :)
int max = 0; | ||
for (Car car : carList) { | ||
car.print(); | ||
if (max < car.getCurrentPosition()) { | ||
max = car.getCurrentPosition(); | ||
result.clear(); | ||
result.add(car); | ||
} else if (max == car.getCurrentPosition()) { | ||
result.add(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.
else 예약어를 쓰지 않는다.
힌트: if 조건절에서 값을 return하는 방식으로 구현하면 else를 사용하지 않아도 된다.
else를 쓰지 말라고 하니 switch/case로 구현하는 경우가 있는데 switch/case도 허용하지 않는다.
else는 사용하지 않고 구현해보시지요~!
indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다.
예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다.
그리고 depth 조건도 위배된 것 같습니다. :)
4단계 구현하였습니다.
구현하면서, 이전 단계에서 피드백주셨던 내용들 반영하였습니다.