-
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
Step3 구현 #6069
base: bo-10000
Are you sure you want to change the base?
Step3 구현 #6069
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.
질문주신 내용에서 테스트 코드를 작성할수 있는 방안을 말씀드렸으니 한번 확인해주세요~
언제든 궁금한게 있다면 슬랙으로 연락주세요!
import java.util.List; | ||
|
||
public class RacingGame { | ||
private final List<Car> cars = new ArrayList<>(); |
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.
한번 Cars에 대해서 일급컬렉션을 만들어보시면 어떨까요?
관련 링크 : https://jojoldu.tistory.com/412
그렇다면 좀더 깔끔하게 구조가 될거 같긴 합니다!
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.
Cars 클래스를 구현했는데 검토부탁드립니다.
각 기능을 Cars와 Car, 그리고 RacingGame 중 어디에 넣어야 할지 애매해서, 재배치가 필요한 부분이 있을지 질문드리고 싶습니다`!
src/main/java/domain/Car.java
Outdated
private int getRandomValue() { | ||
return random.nextInt(10); | ||
} | ||
|
||
private void move(int randomValue) { | ||
if (randomValue >= 4) { | ||
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.
랜덤값으로 인하여, 테스트가 용이하지 않죠.
이런 경우 interface를 통해 확장성을 고려해볼수 있습니다.
https://tecoble.techcourse.co.kr/post/2020-05-17-appropriate_method_for_test_by_interface/
위 글을 참고해서 한번 적용해보시면 테스트 코드 작성이 어렵지 않지 않을까 생각이들어요~
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.
붙혀주신 링크 확인하였습니다! 해당 링크에 있는 방법대로 구현하기 전에 질문드리고 싶은것이 있는데요,
NumberGenerator 관련하여, MovableNumberGenerator의 경우 test만을 위해 새롭게 구현하는 class로 보여지는데, (제가 TDD에 대해 잘 몰라서) 이렇게 test만을 위해 class를 추가하는 것이 전체 코드의 복잡도를 오히려 올리는 것이 아닌지 하는 생각이 들어 의견 여쭤보고 싶습니다!
src/main/java/domain/Car.java
Outdated
import view.ResultView; | ||
|
||
public class Car { | ||
private int position = 0; |
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.
적용했습니다.
관련하여 질문이 있는데, Position을 class로 빼서 구현하다보니 Position class가 하는 일이 그리 많지 않은데요, (값을 증가시키는 기능과 String으로 변환하는 기능)
값을 증가시키는 기능 역시 안의 value를 1 증가시키는 형태라 class로 따로 빼는 형태의 효과를 잘 모르겠습니다.
혹시 Position에 더 많은 역할을 부여해야 할까요?
Step 3의 요구사항은 전부 구현했는데요,
테스트 코드 구현에 어려움이 있습니다.
Car의 method에 대한 테스트를 만드려고 했는데,
테스트를 고려하지 않고 짜다 보니 move와 같은 단일 기능들을 private method로 작성했습니다.
move와 같은 private method의 경우 어떻게 테스트 코드를 만들어야 하는지 궁금합니다.
테스트를 위해서는 전부 public method로 작성해야 할까요?