-
Notifications
You must be signed in to change notification settings - Fork 411
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] 자동차 경주 #874
base: tax1116
Are you sure you want to change the base?
[Step3] 자동차 경주 #874
Conversation
refactor: fix factory method to factory object
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.
자동차 경주 구현 잘해주셨네요 👍
몇가지 생각거리를 남겨두었는데 확인 부탁드립니다 🙏
@@ -14,6 +14,7 @@ dependencies { | |||
testImplementation("org.junit.jupiter", "junit-jupiter", "5.8.2") | |||
testImplementation("org.assertj", "assertj-core", "3.22.0") | |||
testImplementation("io.kotest", "kotest-runner-junit5", "5.2.3") | |||
testImplementation("io.mockk:mockk:1.12.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.
이번 과정을 진행하면서는 mocking 을 이용하기 보다는 테스트 하기 쉬운 구조로 코드를 작성해보세요 😄
import racing.view.InputView | ||
import racing.view.ResultView | ||
|
||
fun main() { |
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.
메인 함수가 깔끔하네요 👍
var position: Int = 1 | ||
private set |
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 setter 정의 👍
fun create(num: Int): List<RacingCar> = | ||
buildList { | ||
for (i in 0 until num) { | ||
this.add(RacingCar()) | ||
} | ||
} |
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.
입력받은 수 만큼 자동차 객체를 생성하는 책임이 RacingCar 클래스에 있는것이 조금 어색한것 같아요.
RacingGame은 사용자의 입력에 따라 자동차 경주에 필요한 자동차를 생성한다.
라는 모델링으로 정의하는것이 자연스러워보이는데, 어떻게 생각하시나요 ?
var position: Int = 1 | ||
private set | ||
|
||
companion object { |
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.
Kotlin의 레이아웃 구성도를 참고해 compaion object 를 배치해보세요 .
https://kotlinlang.org/docs/coding-conventions.html#class-layout
val random = Random.nextInt(RANDOM_RANGE) | ||
if (random >= THRESHOLD) { | ||
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.
자동차의 움직임을 판단하는 기준이 변경되는 경우 어떤 변화가 일어날까요 ?
움직임에 관한 전략을 주입하여 변화에 유연하게 대처하고, 테스트하기 쉬운 구조로 변경해보세요 😄
https://victorydntmd.tistory.com/292
val participants = RacingCar.create(numberOfCar) | ||
val rounds = buildList { | ||
for (id in 1..totalRound) { | ||
this.add(Round(id, participants)) |
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.
Round 객체를 여러개 만들지 않고, totalRound 만큼 loop를 도는건 어떨까요 ?
모든 Round 객체가 동일한 participants를 참조하고 있는데, 어떤 문제점이 있을지 고민해보세요 😄
|
||
private fun inputNumberOfCar(): Int { | ||
println(NUMBER_OF_CAR_QUESTION_TEMPLATE) | ||
return readLine()?.toIntOrNull() ?: throw IllegalArgumentException() |
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.
kotlin 1.6버전 부터 not null을 보장해주는 readln()을 지원합니다.😄
import kotlin.random.Random | ||
import kotlin.random.nextInt | ||
|
||
class RacingCarTest : StringSpec({ |
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.
Kotest 선언 👍
"0~9 중 4미만의 값이 발생하면 정지한다." { | ||
val car = RacingCar() | ||
|
||
mockkObject(Random.Default) { |
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.
앞서 코멘트를 참고하여 mocking 하지 않고 테스트 코드를 작성할수 있는 구조로 만들어보세요 🙏
step3 자동차 경주 구현해보았습니다.
리뷰 부탁드립니다!
감사합니다!