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
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# kotlin-racingcar

###๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ
## ๋ฌธ์ž์—ด ๊ณ„์‚ฐ๊ธฐ

### ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ
- ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋ฌธ์ž์—ด ๊ฐ’์— ๋”ฐ๋ผ ์‚ฌ์น™ ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณ„์‚ฐ๊ธฐ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค.
- ๋ฌธ์ž์—ด ๊ณ„์‚ฐ๊ธฐ๋Š” ์‚ฌ์น™ ์—ฐ์‚ฐ์˜ ๊ณ„์‚ฐ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ์•„๋‹Œ ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ๊ณ„์‚ฐ ์ˆœ์„œ๊ฐ€ ๊ฒฐ์ •๋œ๋‹ค.
- ์˜ˆ๋ฅผ ๋“ค์–ด "2 + 3 * 4 / 2"์™€ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ (2 + 3) * 4 / 2 ์‹คํ–‰ ๊ฒฐ๊ณผ์ธ 10์„ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

###๊ธฐ๋Šฅ ๊ตฌํ˜„ ์‚ฌํ•ญ
### ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์‚ฌํ•ญ
- [X] ๋ง์…ˆ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [X] ๋บ„์…ˆ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
- [X] ๊ณฑ์…ˆ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
Expand All @@ -14,5 +16,27 @@
- [X] ์ž…๋ ฅ๊ฐ’์ด ์‚ฌ์น™์—ฐ์‚ฐ ๊ธฐํ˜ธ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ด์•ผ ํ•œ๋‹ค.
- [X] ์‚ฌ์น™ ์—ฐ์‚ฐ์„ ๋ชจ๋‘ ํฌํ•จํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค.

###ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ
### ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ
- ๋ฉ”์„œ๋“œ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ์ผ์„ ํ•˜์ง€ ์•Š๋„๋ก ๋ถ„๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค.

## ์ž๋™์ฐจ ๊ฒฝ์ฃผ

### ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ
์ดˆ๊ฐ„๋‹จ ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„์„ ๊ตฌํ˜„ํ•œ๋‹ค.
- ์ฃผ์–ด์ง„ ํšŸ์ˆ˜ ๋™์•ˆ N๋Œ€์˜ ์ž๋™์ฐจ๋Š” ์ „์ง„ ๋˜๋Š” ๋ฉˆ์ถœ ์ˆ˜ ์žˆ๋‹ค.
- ์‚ฌ์šฉ์ž๋Š” ๋ช‡ ๋Œ€์˜ ์ž๋™์ฐจ๋กœ ๋ช‡ ๋ฒˆ์˜ ์ด๋™์„ ํ•  ๊ฒƒ์ธ์ง€๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
- ์ „์ง„ํ•˜๋Š” ์กฐ๊ฑด์€ 0์—์„œ 9 ์‚ฌ์ด์—์„œ ๋ฌด์ž‘์œ„ ๊ฐ’์„ ๊ตฌํ•œ ํ›„ ๋ฌด์ž‘์œ„ ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ์ด๋‹ค.
- ์ž๋™์ฐจ์˜ ์ƒํƒœ๋ฅผ ํ™”๋ฉด์— ์ถœ๋ ฅํ•œ๋‹ค. ์–ด๋Š ์‹œ์ ์— ์ถœ๋ ฅํ•  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ์ œ์•ฝ์€ ์—†๋‹ค.

### ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์‚ฌํ•ญ
- [X] ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ž๋™์ฐจ ๋Œ€์ˆ˜์™€ ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.
- [X] ๊ฒฝ์ฃผ ๊ฒŒ์ž„์€ ์ž…๋ ฅ๊ฐ’๋งŒํผ์˜ ์ž๋™์ฐจ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
- [X] ๊ฒฝ์ฃผ ๊ฒŒ์ž„์€ 0์—์„œ 9 ์‚ฌ์ด์—์„œ ๋ฌด์ž‘์œ„ ๊ฐ’์„ ๊ตฌํ•œ๋‹ค.
- [X] ์ž๋™์ฐจ๋Š” ๋ฌด์ž‘์œ„ ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ์ „์ง„ํ•œ๋‹ค.
- [X] ์ž๋™์ฐจ๋Š” ๋ฌด์ž‘์œ„ ๊ฐ’์ด 4 ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ์ •์ง€ํ•œ๋‹ค.
- [X] ๊ฒฝ์ฃผ ๊ฒŒ์ž„์€ ๋ชจ๋“  ์ž๋™์ฐจ์— ๋Œ€ํ•ด ๋ฌด์ž‘์œ„ ๊ฐ’์„ ๊ตฌํ•˜์—ฌ ์ด๋™์‹œํ‚จ๋‹ค.
- [X] ๊ฒฝ์ฃผ ๊ฒŒ์ž„์˜ ๊ฒฐ๊ณผ๋ฅผ ๊ฒฐ๊ณผ ํ™”๋ฉด์„ ํ†ตํ•ด ์ถœ๋ ฅํ•œ๋‹ค.

### ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ
- [X] ๋ชจ๋“  ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.
- [X] ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง(InputView, ResultView)์„ ๊ตฌ๋ถ„ํ•œ๋‹ค.
15 changes: 15 additions & 0 deletions src/main/kotlin/racingcar/Car.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package racingcar

class Car {
var position: Int = DEFAULT_POSITION
private set

fun move(value: Int) {
if (value >= FORWARD_NUMBER) position++
}

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
}

private const val FORWARD_NUMBER = 4
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/racingcar/InputView.kt
Original file line number Diff line number Diff line change
@@ -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๋กœ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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()
...

println("์ž๋™์ฐจ ๋Œ€์ˆ˜๋Š” ๋ช‡ ๋Œ€์ธ๊ฐ€์š”?")
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์—์„œ ์ถœ๋ ฅํ•ด์•ผ ํ•˜์ง€ ์•Š์„๊นŒ์š”?


return numberOfCars to count
}
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/racingcar/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package racingcar

fun main() {
val racingGame = RacingGame()

val (numberOfCars, count) = InputView.view()
racingGame.set(numberOfCars, count)

for (i in 1..count) {
racingGame.run()
ResultView.view(racingGame.carList)
}
}
37 changes: 37 additions & 0 deletions src/main/kotlin/racingcar/RacingGame.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package racingcar

import kotlin.random.Random

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

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


fun set(numberOfCars: Int, count: Int) {
val carMList: MutableList<Car> = mutableListOf()
for (i in 1..numberOfCars) {
carMList.add(Car())
}
carList = carMList.toList()
randomNumberList = Array(count) { IntArray(numberOfCars) }
}

fun run() {
for (i in carList.indices) {
val randomNumber = random()
carList[i].move(randomNumber)
randomNumberList[times][i] = randomNumber
}
times++
}

private fun random(): Int {
return Random.nextInt(MAX_RANDOM_NUMBER)
}

companion object {
private const val MAX_RANDOM_NUMBER: Int = 9
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/racingcar/ResultView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package racingcar

class ResultView {
companion object {
fun view(cars: List<Car>) {
for (car in cars) {
if (car.position == 0) println("x")
else println("-".repeat(car.position))
}
println()
}
}
}
37 changes: 37 additions & 0 deletions src/main/kotlin/racingcar/feedback/Car.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package racingcar.feedback

// ์ƒ์ˆ˜๋ฅผ ์ตœ์ƒ์œ„ ์ˆ˜์ค€๊ณผ ๋™๋ฐ˜ ๊ฐ์ฒด ์ค‘ ๋ฌด์—‡์œผ๋กœ ์ •์˜ํ•˜๋Š๋ƒ๋Š” ์ƒ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค์˜ ๋ฒ”์œ„์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค!
// ๋งŒ์•ฝ์— ์ƒ์ˆ˜๋ฅผ ์ตœ์ƒ์œ„ ์ˆ˜์ค€์—์„œ ์„ ์–ธํ•˜๋ฉด ์ฝ”ํ‹€๋ฆฐ์€ CarKt ์ด๋ผ๋Š” ํด๋ž˜์Šค ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ ๋ชจ์•„๋‘”๋‹ค.
// private const val ...

object Numbers {
// ์ตœ์ƒ์œ„ ์ˆ˜์ค€์œผ๋กœ ์„ ์–ธํ–ˆ์„ ๋•Œ์˜ ๋‹จ์ ์€ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ์ƒ์ˆ˜ ์ด๋ฆ„์„ ์•Œ์•„์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.
// ๊ทธ๋ž˜์„œ object ์•ˆ์— ์ƒ์ˆ˜๋ฅผ ์„ ์–ธํ•ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•œ๋‹ค.
const val MAXIMUM_NAME_LENGTH: Int = 5
}

class Car(val name: String, position: Int = DEFAULT_POSITION) {
var position: Int = position
private set // ์ปค์Šคํ…€ ๊ฒŒํ„ฐ์™€ ์„ธํ„ฐ๋Š” ์ƒ์„ฑ์ž์—์„œ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค!
/*
private var _position: Int = position
val position: Int
get() = _position
*/

init {
require(name.length <= Numbers.MAXIMUM_NAME_LENGTH) { "์ž๋™์ฐจ ์ด๋ฆ„์€ 5๊ธ€์ž๋ฅผ ๋„˜๊ธธ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค." }
}

fun move() {
position++
}

companion object {
private const val DEFAULT_POSITION: Int = 0

@JvmField
val DEFAULT_CAR: Car = Car("")
fun of(name: String): Car = Car(name)
}
}
19 changes: 19 additions & 0 deletions src/main/kotlin/racingcar/feedback/Numbers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@file:JvmName("NumberUtils")

package racingcar.feedback

const val FORWARD_NUMBER: Int = 4

fun calculate(text: String?): Int {
require(!text.isNullOrBlank()) { "์ž…๋ ฅ๊ฐ’์ด null ๋˜๋Š” ๋นˆ ๋ฌธ์ž์—ด์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค." }
run(!text.isNullOrBlank()) { "์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค." } // ์ปค์Šคํ…€ ์˜ˆ์™ธ์— ๋Œ€ํ•ด์„œ ์ง์ ‘ ๋งŒ๋“ค์–ด ์จ๋ณด์ž!
// ...
return 0
}

fun run(value: Boolean, lazyMessage: () -> Any) {
if (!value) {
val message = lazyMessage()
throw RuntimeException(message.toString())
}
}
33 changes: 33 additions & 0 deletions src/test/kotlin/racingcar/CarTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package racingcar

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

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.

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

// given
val car = Car()

// when
car.move(input)

// then
assertThat(car.position).isEqualTo(1)
}

@ParameterizedTest
@ValueSource(ints = [1, 2, 3])
fun `์ž๋™์ฐจ๋Š” ๋ฌด์ž‘์œ„ ๊ฐ’์ด 4 ๋ฏธ๋งŒ์ผ ๊ฒฝ์šฐ ์ •์ง€ํ•œ๋‹ค`(input: Int) {
// given
val car = Car()

// when
car.move(input)

// then
assertThat(car.position).isEqualTo(0)
}
}
37 changes: 37 additions & 0 deletions src/test/kotlin/racingcar/RacingGameTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package racingcar

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class RacingGameTest {
@Test
fun `๊ฒฝ์ฃผ ๊ฒŒ์ž„์€ ์ž…๋ ฅ๊ฐ’๋งŒํผ์˜ ์ž๋™์ฐจ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค`() {
// given
val racingGame = RacingGame()

// when
racingGame.set(3, 5)

// then
assertThat(racingGame.carList.size).isEqualTo(3)
}

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

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

...

}
42 changes: 42 additions & 0 deletions src/test/kotlin/racingcar/feedback/CarTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package racingcar.feedback

import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test

class CarTest {
@Test
fun `์ž๋™์ฐจ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค`() {
val car = Car("jason", 0)
assertThat(car.name).isEqualTo("jason")
assertThat(car.position).isEqualTo(0)
}

@Test
fun `๊ธฐ๋ณธ ์ธ์ž๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ž๋™์ฐจ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค`() {
val car = Car("jason")
assertThat(car.name).isEqualTo("jason")
assertThat(car.position).isEqualTo(0)
}

@Test
fun `์ž๋™์ฐจ์˜ ์ด๋ฆ„์ด 5๊ธ€์ž๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚จ๋‹ค`() {
assertThatExceptionOfType(IllegalArgumentException::class.java).isThrownBy {
Car("๊ฐ€๋‚˜๋‹ค๋ผ๋งˆ๋ฐ”์‚ฌ")
}
}

@Test
fun `ํŒฉํ† ๋ฆฌ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž๋™์ฐจ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค`() {
val car = Car.of("jason")
assertThat(car.name).isEqualTo("jason")
assertThat(car.position).isEqualTo(0)
}

@Test
fun `์ •์  ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค`() {
val car = Car.DEFAULT_CAR
assertThat(car.name).isEqualTo("")
assertThat(car.position).isEqualTo(0)
}
}
13 changes: 13 additions & 0 deletions src/test/kotlin/racingcar/feedback/JavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package racingcar.feedback;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class NumberUtilsTest {
@Test
void ์ฝ”ํ‹€๋ฆฐ์ƒ์ˆ˜() {
assertThat(NumberUtils.FORWARD_NUMBER).isEqualTo(4);
Car defaultCar = Car.DEFAULT_CAR;
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/study/PersonKoTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package study

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.shouldBe

class PersonKoTest : StringSpec({
"์ด๋ฆ„ ๋ถ™์ธ ์ธ์ž" {
Expand Down