Skip to content
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

Open
wants to merge 10 commits into
base: ajy9844
Choose a base branch
from

Conversation

ajy9844
Copy link

@ajy9844 ajy9844 commented Nov 20, 2022

์•ˆ๋…•ํ•˜์„ธ์š” ์˜์ง ๋ฆฌ๋ทฐ์–ด๋‹˜!
3๋‹จ๊ณ„ ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๋ฏธ์…˜ ๋ฆฌ๋ทฐ ์š”์ฒญ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. (๋งŽ์ด ๋Šฆ์–ด์ ธ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜ญ)

์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ ์ƒ๊ธด ์งˆ๋ฌธ์€ ์ฝ”๋ฉ˜ํŠธ๋กœ ๋‹ฌ์•„๋‘๊ฒ ์Šต๋‹ˆ๋‹ค!
์ด๋ฒˆ์—๋„ ๊ณ ์น˜๋ฉด ์ข‹์„ ๋ถ€๋ถ„์— ๋Œ€ํ•ด ๋งŽ์ด ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
์‹œ๊ฐ„ ๋‚ด์–ด ๋ฆฌ๋ทฐํ•ด ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

Copy link

@laco-dev laco-dev left a 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

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 {

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> {

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("์‹คํ–‰ ๊ฒฐ๊ณผ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"์‹คํ–‰ ๊ฒฐ๊ณผ"๋Š” ResultView์—์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ์š”?

Comment on lines +6 to +10
lateinit var carList: List<Car>
private set
lateinit var randomNumberList: Array<IntArray>
private set
private var times: Int = 0

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, ...) { ... }
}

Comment on lines +19 to +36
@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)
}
}

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž๋™์ฐจ์˜ ๊ฒฝ์šฐ ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์ด "๋ฌด์ž‘์œ„" ๋ผ๋Š” ์‚ฌ์‹ค์— ๊ด€์‹ฌ์ด ์žˆ์„๊นŒ์š”?

- ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ด€๋ จ ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ ์ถ”๊ฐ€
- ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ด€๋ จ ๊ธฐ๋Šฅ ๊ตฌํ˜„์‚ฌํ•ญ ์ถ”๊ฐ€
- ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ด€๋ จ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ์‚ฌํ•ญ ์ถ”๊ฐ€
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants