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

Step5 #1194

Open
wants to merge 17 commits into
base: minhyukseul
Choose a base branch
from
Open

Step5 #1194

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
52d4703
step3:racingCar done
minhyukseul Jun 8, 2023
0e148b1
step3: 구조 변경에 따른 수정
Jun 9, 2023
92bda41
step3: behaviorTest 추가
minhyukseul Jun 9, 2023
a284070
fix : 기존 이슈 충돌 수정
minhyukseul Jun 10, 2023
5f76e5e
refactor : 리뷰 반영에 따른 리팩토링 적용
minhyukseul Jun 11, 2023
8861db1
refactor : 리뷰 반영에 따른 리팩토링 적용
minhyukseul Jun 11, 2023
b8ceef2
feat : 1. 입력 클래스 설정 및 구현
minhyukseul Jun 11, 2023
5550155
feat : 입력 클래스 설정, 출력 클래스 설정, Main 함수 구현 및 리팩토링 진행
minhyukseul Jun 12, 2023
78aa106
refactoring : klint 수정
minhyukseul Jun 12, 2023
6a6f517
refactoring : 자동차 random 숫자 생성을 외부에서 하도록 수정. 그 외 코드 리팩토링 진행
minhyukseul Jun 13, 2023
b8417a8
refactoring: 코드 리팩토링 진행진행
minhyukseul Jun 13, 2023
e658642
feat: 자동차 이름과 위치에 대한 기본 단위 테스트 및 패키지 분리
minhyukseul Jun 14, 2023
e037f1f
feat: 자동차 이름은 쉼표(,)를 기준으로 구분
minhyukseul Jun 14, 2023
894f865
feat: 0에서 9 사이에서 무작위 값을 구현테스트 작성
minhyukseul Jun 14, 2023
8dc62b7
feat: 전진하는 자동차를 출력할 때 자동차 이름을 같이 출력 단위테스트 구현
minhyukseul Jun 14, 2023
01572ba
feat: 자동차 경주 게임을 완료한 후 누가 우승했는지 단위테스트 구현 및 main controller로직 구현완료
minhyukseul Jun 14, 2023
d2377d0
feat: ktlint적용
minhyukseul Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@
- [x] 들여쓰기 2 넘지 않도록 구현
- [x] 함수 이름 15라인 넘지 않도록 구현
5. 단위 테스트 구현
- [x] 자동차 random이 구현 범위내에 들어오는지 체크
- [x] 자동차 random이 구현 범위내에 들어오는지 체크

### STEP5 리팩토링

- [x] 자동차는 이름을 가지고 최초 위치는 0을 가리킨다.
- [x] 자동차 이름은 5자를 초과할 수 없다.
- [x] 자동차 이름은 쉼표(,)를 기준으로 구분한다.
- [x] 0에서 9 사이에서 무작위 값을 구한다.
- [x] 전진하는 자동차를 출력할 때 자동차 이름을 같이 출력한다.
- [x] 자동차 경주 게임을 완료한 후 누가 우승했는지를 알려준다. 우승자는 한 명 이상일 수 있다.
- [x] 핵심 비지니스 로직을 가지는 객체를 domain패키지, UI관련한 객체를 view패키지에 구현
- [x] MVC패턴 기반으로 리팩토링, view 패키지의 객체가 domain 패키지에 의존할 수 있음, domain패키지의 객체는 view 패키지에 의존하지 않도록 구현
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
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.5.0")
testImplementation("io.kotest", "kotest-runner-junit5", "5.6.2")
}

tasks {
Expand Down
27 changes: 0 additions & 27 deletions src/main/kotlin/Car.kt

This file was deleted.

30 changes: 0 additions & 30 deletions src/main/kotlin/InputView.kt

This file was deleted.

14 changes: 0 additions & 14 deletions src/main/kotlin/RagingCarMain.kt

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/kotlin/ResultView.kt

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/kotlin/racing/InputParser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racing

object InputParser {

private const val INPUT_SEPERATOR = ","
fun parse(carNames: String): List<String> {
return carNames.split(INPUT_SEPERATOR)
}
}
14 changes: 13 additions & 1 deletion src/main/kotlin/racing/RagingCarMain.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package racing

import racing.domain.Car
import racing.domain.RacingGame
import racing.view.InputView
import racing.view.ResultView

fun main() {
val inputData = InputView.doInput()
val carNames = inputData.first
val actionCount = inputData.second
val cars = carNames.map {
Car(it)
}
ResultView.showResult(cars, actionCount)

repeat(actionCount) {
RacingGame.raceStart(cars)
ResultView.showSkidMarks(cars)
ResultView.printEnter()
}
ResultView.showWinner(cars)
}
40 changes: 0 additions & 40 deletions src/main/kotlin/racing/ResultView.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package racing
package racing.domain

class Car(val name: String) {

var progress = 0
var position = DEFAULT_POSITION
private set

init {
Expand All @@ -11,14 +11,16 @@ class Car(val name: String) {
}
}

fun moveCar(pedalStrength: Int): Int {
fun moveCar(pedalStrength: Int): Boolean {
if (pedalStrength >= GO_RESTRICT_STRENGTH) {
progress++
position++
return true
}
return progress
return false
}

companion object {
const val DEFAULT_POSITION = 0
const val GO_RESTRICT_STRENGTH = 4
const val MAXIMUM_NAME_LENGTH = 5
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/racing/domain/RacingGame.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package racing.domain

import racing.CarRandomGenerator

object RacingGame {

const val MAX_BOUND = 10

fun raceStart(cars: List<Car>) {
cars.forEach {
it.moveCar(CarRandomGenerator.createRandom(MAX_BOUND))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package racing
package racing.view

import racing.InputParser

object InputView {

private const val DEFAULT_INPUT = 0
private const val MINIMUM_INPUT = 1

private const val INPUT_SEPERATOR = ","

private const val INPUT_ACTION_PREFIX = "시도할 횟수는 "

fun doInput(): Pair<List<String>, Int> {
Expand All @@ -18,14 +18,14 @@ object InputView {
if (actionCount < MINIMUM_INPUT) {
throw IllegalArgumentException("$INPUT_ACTION_PREFIX ${MINIMUM_INPUT}대 이상이어야 함")
}
return Pair(carNames, actionCount)
return carNames to actionCount
}

private fun getInputCars(): List<String> {
return runCatching {
val inputCars = (readlnOrNull() ?: "")
if (inputCars.isEmpty()) throw IllegalArgumentException("이름은 한글자 이상이어야 함")
inputCars.split(INPUT_SEPERATOR)
val inputCars = readlnOrNull()
if (inputCars.isNullOrEmpty()) throw IllegalArgumentException("이름은 한글자 이상이어야 함")
InputParser.parse(inputCars)
}.getOrElse {
throw IllegalArgumentException("형식에 맞는 타입을 입력해야함")
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/kotlin/racing/view/ResultView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package racing.view

import racing.domain.Car

object ResultView {
private const val PROGRESS_STRING = "-"
private const val SEPERATOR = ", "
fun showWinner(cars: List<Car>) {
val firstGradePosition = cars.maxOf(Car::position)
val winners = cars.filter {
it.position == firstGradePosition
}.joinToString(SEPERATOR, transform = Car::name)
print("${winners}가 최종 우승했습니다.")
}

fun showSkidMarks(cars: List<Car>) {
cars.forEach { car ->
val progressString = StringBuffer()
repeat(car.position) {
progressString.append(PROGRESS_STRING)
}
println("${car.name} : $progressString")
}
}

fun printEnter() {
println()
}
}
43 changes: 0 additions & 43 deletions src/test/kotlin/racing/CarTest.kt

This file was deleted.

Loading