-
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
๐ 3๋จ๊ณ - ์๋์ฐจ ๊ฒฝ์ฃผ #907
base: ajy9844
Are you sure you want to change the base?
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.
์๋์ฐจ ๊ฒฝ์ฃผ ๋ฏธ์
์ ํด์ฃผ์
จ์ต๋๋ค.
์ง๋ ๋ฏธ์
๊น์ง ๊ฐ์ ํ ๋ด์ฉ๋ ๊ฐ์ด ๋ฐ์์ ํด์ฃผ์
จ๋ค์. ๐๐ป
์ฝํ๋ฆฐ์ ๋ฐฐ์๊ฐ๋ ๊ณผ์ ์์ ํ์ํ ๋ช๊ฐ์ง ๋ด์ฉ๊ณผ ํจ๊ป ๊ณ ๋ฏผํด๋ณผ๋งํ ์ ์ ๊ฐ์ด ๋จ๊ฒจ ๋ณด์์ต๋๋ค.
} | ||
|
||
companion object { | ||
private const val DEFAULT_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.
์ฐจ๋์ ์ด๊ธฐ ์์น์ ๋ํ ํ
์คํธ๋ ์์ฑ ํด ๋ณด์ธ์.
์ด ๊ฒฝ์ฐ ์์ฑ์๋ฅผ ํตํด ์ฐจ๋์ ์ด๊ธฐ ์์น๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ํ๋ฉด ํ
์คํธ๋ฅผ ๋ณด๋ค ํจ์จ์ ์ผ๋ก ์์ฑํ ์ ์์ต๋๋ค.
class Car(initialPosition: Int = DEFAULT_POSITION) {
var position: Int = initialPosition
private set
}
@@ -0,0 +1,15 @@ | |||
package racingcar | |||
|
|||
class InputView { |
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.
์ ๊ณตํ๋ ํจ์๊ฐ ์ ์ ๋ฉ์๋๋ฐ์ ์๋ ๊ฒฝ์ฐ์๋ class ๋์ object๋ก ๋ง๋ค์ด์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
|
||
class InputView { | ||
companion object { | ||
fun view(): Pair<Int, Int> { |
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()๊ฐ ๋ฌด์จ ๊ฐ์ ๋ฐํํ๋์ง ์ ์ ์์๊น์?
์ฌ์ฉํ๋ ๊ณณ์ ์ฝ๋๋ฅผ ์ค์ด๋ ค๊ณ ํ๋ ๊ฒ ๋ณด๋ค ์คํ๋ ค ๊ฐ๋
์ฑ์ด ๋จ์ด์ง ์ ์์ต๋๋ค.
๋ช
ํํ๊ฒ ํจ์๋ฅผ ๋ถ๋ฆฌํด์ ๋ฐ์๋ณด๋ฉด ์ด๋จ๊น์?
InputView.getNumberOfCars()
InputView.getTryCount()
...
val numberOfCars = readLine()!!.toInt() | ||
println("์๋ํ ํ์๋ ๋ช ํ์ธ๊ฐ์?") | ||
val count = readLine()!!.toInt() | ||
println("์คํ ๊ฒฐ๊ณผ") |
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.
"์คํ ๊ฒฐ๊ณผ"๋ ResultView์์ ์ถ๋ ฅํด์ผ ํ์ง ์์๊น์?
lateinit var carList: List<Car> | ||
private set | ||
lateinit var randomNumberList: Array<IntArray> | ||
private set | ||
private var times: Int = 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.
์ง์ฐ์ด๊ธฐํ๋ฅผ ์ด์ฉํ๋ ๊ฒ์ด ์ด๋ค ์ฅ์ ์ด ์์๊น์?
RacingGame์ ์ํ๊ฐ ๊ณ์ํด์ ๋ณ๊ฒฝ์ด๋๋ฉด์ ์ฌํ์ฉ ๋ ๊ฒฝ์ฐ๋ ์๋ค๊ณ ์๊ฐ์ด ๋ญ๋๋ค.
ํ๋ฒ์ ๊ฒฝ์ฃผ์์ ํ๋ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๋ง๋ค์ด ๋ด๋๋ก ํ๋ฉด ์ด๋จ๊น์?
object RacingGame {
fun race(cars: List<Car>, times: Int, ...) { ... }
}
@Test | ||
fun `๊ฒฝ์ฃผ ๊ฒ์์ ๋ชจ๋ ์๋์ฐจ์ ๋ํด ๋ฌด์์ ๊ฐ์ ๊ตฌํ์ฌ ์ด๋์ํจ๋ค`() { | ||
// given | ||
val racingGame = RacingGame() | ||
racingGame.set(3, 1) | ||
|
||
// when | ||
racingGame.run() | ||
|
||
// then | ||
val cars = racingGame.carList | ||
val numbers = racingGame.randomNumberList[0] | ||
|
||
for (i in cars.indices) { | ||
if (numbers[i] >= 4) assertThat(cars[i].position).isEqualTo(1) | ||
else assertThat(cars[i].position).isEqualTo(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.
ํ
์คํธ ์ฝ๋์์๋ ๋ฌด์์๋ผ๋ ๋ถํ์ค์ฑ์ ํ
์คํธ ํ๋ ๊ฒ์ ์๋นํ ์ด๋ ต์ต๋๋ค.
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ฐ๋ฆฌ๋ ์์กด์ฑ ์ฃผ์
๊ณผ ๊ฐ์ ๋ฐฉ์์ ์ด์ฉํด ๋๋ฉ์ธ ๋ก์ง์๋ง ํ
์คํธ ํ๋๋ก ์ง์ค์ ํ ์ ์์ด์.
์ฐจ๋์ด ์ด๋ ๊ฐ๋ฅํ์ง์ ๋ํ ์กฐ๊ฑด์ ์ ํ๊ณ , ๊ฐ๊ฐ ๊ตฌํํ๋๋ก ๋ง๋ค์ด์ ์๋์ฐจ์ ์ด๋ ์กฐ๊ฑด์ ํ ์คํธ์์ ์ ์ด๊ฐ ๊ฐ๋ฅํ๋๋ก ๋ง๋ค์ด ๋ณด์ธ์.
// Hint
interface CarMoveable {
fun getMovementValue(): Int
}
class RandomCarMoveable: CarMoveable {
override fun getMovementValue(): Int { ... }
}
object AlwaysForwardCarMoveable: CarMoveable {
override fun getMovementValue(): Int { return 4 }
}
...
class CarTest { | ||
@ParameterizedTest | ||
@ValueSource(ints = [4, 5, 6]) | ||
fun `์๋์ฐจ๋ ๋ฌด์์ ๊ฐ์ด 4 ์ด์์ผ ๊ฒฝ์ฐ ์ ์งํ๋ค`(input: Int) { |
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.
์๋์ฐจ์ ๊ฒฝ์ฐ ์ ๋ ฅ๋ฐ์ ๊ฐ์ด "๋ฌด์์" ๋ผ๋ ์ฌ์ค์ ๊ด์ฌ์ด ์์๊น์?
- ์๋์ฐจ ๊ฒฝ์ฃผ ๊ด๋ จ ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ ์ถ๊ฐ - ์๋์ฐจ ๊ฒฝ์ฃผ ๊ด๋ จ ๊ธฐ๋ฅ ๊ตฌํ์ฌํญ ์ถ๊ฐ - ์๋์ฐจ ๊ฒฝ์ฃผ ๊ด๋ จ ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ์ฌํญ ์ถ๊ฐ
์๋ ํ์ธ์ ์์ง ๋ฆฌ๋ทฐ์ด๋!
3๋จ๊ณ ์๋์ฐจ ๊ฒฝ์ฃผ ๋ฏธ์ ๋ฆฌ๋ทฐ ์์ฒญ ๋๋ฆฝ๋๋ค. (๋ง์ด ๋ฆ์ด์ ธ ์ฃ์กํฉ๋๋ค๐ญ)
์ฝ๋๋ฅผ ์์ฑํ๋ฉด์ ์๊ธด ์ง๋ฌธ์ ์ฝ๋ฉํธ๋ก ๋ฌ์๋๊ฒ ์ต๋๋ค!
์ด๋ฒ์๋ ๊ณ ์น๋ฉด ์ข์ ๋ถ๋ถ์ ๋ํด ๋ง์ด ์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
์๊ฐ ๋ด์ด ๋ฆฌ๋ทฐํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค!