From 30dbddcc3f26e9db609e512fef17aeb3d1faff42 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Thu, 24 Oct 2024 01:04:10 +0900 Subject: [PATCH 01/43] =?UTF-8?q?docs:=20`README.md`=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 구현 기능 목록, 프로그래밍 요구사항, 라이브러리 작성 --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 62fa463c..3b438421 100644 --- a/README.md +++ b/README.md @@ -1 +1,31 @@ # kotlin-racingcar-precourse + +초간단 자동차 경주 게임을 구현한다. + +# 구현 기능 목록 + +- 몇 번 이동할 것인지 횟수 입력 기능 +- 자동차의 이름 입력 기능 + - 쉼표(`,`) 기준으로 한 번에 n 대의 이름 입력 받기 + - 해당 기능에서 자동차 갯수 확인 + - 각각의 이름은 5자 이하 +- 자동차의 전진 기능 + - 전진 조건은 0~9 사이 무작위 값이 4 이상일 경우 +- 각 실행 결과 출력 기능 +- 우승자 출력 기능 + - 우승자는 한 명 이상일 수 있음 + - 쉼표(`,`)로 우승자 여러 명 출력 +- 잘못된 입력값에 대해 IllegalArgumentException 발생 기능 + +# 프로그래밍 요구사항 + +- 외부 라이브러리 사용 불가 +- `Kotlin Style Guide` 원칙 +- `indent depth` 2 이하로 구현할 것 +- 함수는 한 가지 일만 담당하게끔 구현 +- 위의 기능 목록에 대해 각각을 테스트할 것 + +# 라이브러리 +- `camp.nextstep.edu.missionutils` + - `Randoms.pickNumberInRange()` + - `Console.readLine()` \ No newline at end of file From bf650ccb77197e5864b1edb846cac7c03dd50bf6 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:58:18 +0900 Subject: [PATCH 02/43] =?UTF-8?q?feat:=20=EC=83=81=EC=88=98=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Constants.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/kotlin/racingcar/Constants.kt diff --git a/src/main/kotlin/racingcar/Constants.kt b/src/main/kotlin/racingcar/Constants.kt new file mode 100644 index 00000000..c832afb1 --- /dev/null +++ b/src/main/kotlin/racingcar/Constants.kt @@ -0,0 +1,6 @@ +package racingcar + +object Constants { + const val MESSAGE_INPUT_CAR_NAME = "경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)" + const val MESSAGE_INPUT_ATTEMPT_NUMBER = "시도할 횟수는 몇 회인가요?" +} \ No newline at end of file From 4a7aebdf5170811bab8e9c2738d3143706702e46 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:27:26 +0900 Subject: [PATCH 03/43] =?UTF-8?q?docs:=20=EC=A4=91=EC=9A=94=EB=8F=84?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=98=EB=B0=8D=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b438421..03c16513 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ # 프로그래밍 요구사항 -- 외부 라이브러리 사용 불가 -- `Kotlin Style Guide` 원칙 -- `indent depth` 2 이하로 구현할 것 +- **`indent depth` 2 이하로 구현할 것** - 함수는 한 가지 일만 담당하게끔 구현 - 위의 기능 목록에 대해 각각을 테스트할 것 +- 외부 라이브러리 사용 불가 +- `Kotlin Style Guide` 원칙 # 라이브러리 - `camp.nextstep.edu.missionutils` From 2af0f9fa4d8dfd67909e86e7dc4ff44a464771c5 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:29:45 +0900 Subject: [PATCH 04/43] =?UTF-8?q?docs($README):=20=EC=8A=88=EB=8F=84=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03c16513..edcbeaa5 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,21 @@ # 라이브러리 - `camp.nextstep.edu.missionutils` - `Randoms.pickNumberInRange()` - - `Console.readLine()` \ No newline at end of file + - `Console.readLine()` + +--- + +# 슈도 코드 작성 + +```kotlin +val carMap: Map +val attemptNumber: Int + +for (attemptNumber) { + randomDice(carMap) + printRaceResult(carMap) // carMap의 Int 이용 +} + +val winner = getWinner(carMap) // carMap의 Int 이용 최댓값 추출 +printWinner(winner) +``` From b798892bea3b6d6eb62a25855342915e1d74ad29 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Sat, 26 Oct 2024 00:24:36 +0900 Subject: [PATCH 05/43] =?UTF-8?q?docs:=20=EC=8B=A4=ED=96=89=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=98=88=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index edcbeaa5..96bd7ecf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,37 @@ - `Randoms.pickNumberInRange()` - `Console.readLine()` +# 실행 결과 예시 +``` +경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분) +pobi,woni,jun +시도할 횟수는 몇 회인가요? +5 + +실행 결과 +pobi : - +woni : +jun : - + +pobi : -- +woni : - +jun : -- + +pobi : --- +woni : -- +jun : --- + +pobi : ---- +woni : --- +jun : ---- + +pobi : ----- +woni : ---- +jun : ----- + +최종 우승자 : pobi, jun +``` + --- # 슈도 코드 작성 From e3ea0ead756bdc10767575cd425393bc56480aa0 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Sun, 27 Oct 2024 01:38:45 +0900 Subject: [PATCH 06/43] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0d8f3a79..868bdb67 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -1,5 +1,13 @@ package racingcar +import camp.nextstep.edu.missionutils.Console.readLine + fun main() { - // TODO: 프로그램 구현 + val carMap = mutableMapOf() + + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + // TODO : trim() ? 으로 공백 제거? // 커밋 body에 올렸다 PR 설명에 적기 + for (i in readLine().split(",")) { + carMap.put(i, 0) + } } From 2cfaa444c4c0c4b6039d678a3d094820ee67ae6b Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Sun, 27 Oct 2024 01:39:48 +0900 Subject: [PATCH 07/43] =?UTF-8?q?feat:=20=EC=9D=B4=EB=8F=99=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 868bdb67..997fab3e 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -10,4 +10,7 @@ fun main() { for (i in readLine().split(",")) { carMap.put(i, 0) } + + println("시도할 횟수는 몇 회인가요?") + val attemptNumber = readLine().toInt() // TODO : 위치 변경? } From dd97387b4801b5959890bb06c5869fa2792e894e Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 01:12:48 +0900 Subject: [PATCH 08/43] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=EC=9D=98=20=EC=A0=84=EC=A7=84=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 전진 조건인 무작위 값 4 이상의 조건을 만족시키기 위해 `pickNumberInRange()` 사용 --- src/main/kotlin/racingcar/Application.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 997fab3e..a1b0e2dd 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -1,6 +1,7 @@ package racingcar import camp.nextstep.edu.missionutils.Console.readLine +import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange fun main() { val carMap = mutableMapOf() @@ -13,4 +14,13 @@ fun main() { println("시도할 횟수는 몇 회인가요?") val attemptNumber = readLine().toInt() // TODO : 위치 변경? + + for (i in 0 until attemptNumber) { + carMap.forEach { key, value -> + if (pickNumberInRange(0,9) >= 4) { + carMap[key] = value + 1 + } + } + } + } From 85cb6fceb1657c671bb3e857174d2d4c95ae3fd3 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:32:31 +0900 Subject: [PATCH 09/43] =?UTF-8?q?feat:=20=EA=B0=81=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index a1b0e2dd..4778d4ed 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -15,12 +15,15 @@ fun main() { println("시도할 횟수는 몇 회인가요?") val attemptNumber = readLine().toInt() // TODO : 위치 변경? + println("실행 결과") for (i in 0 until attemptNumber) { carMap.forEach { key, value -> if (pickNumberInRange(0,9) >= 4) { carMap[key] = value + 1 } + + println("$key : " + "-".repeat(carMap[key]!!)) } + println() } - } From 70006e75fd5c1fad0293f472e06f99c98c3fdbe6 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:58:36 +0900 Subject: [PATCH 10/43] =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 우승자는 한 명 이상일 수 있음 - 쉼표(,)로 우승자 여러 명 출력 --- src/main/kotlin/racingcar/Application.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 4778d4ed..d81dd12d 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -24,6 +24,14 @@ fun main() { println("$key : " + "-".repeat(carMap[key]!!)) } + println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 println() } + + // TODO: 함수 분리할 것 + println( + "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } + .keys + .joinToString(", "), + ) } From 264b9df83d524487b19835d9a64304aa32d31473 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:03:33 +0900 Subject: [PATCH 11/43] =?UTF-8?q?Revert=20"=EC=9A=B0=EC=8A=B9=EC=9E=90=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 70006e75fd5c1fad0293f472e06f99c98c3fdbe6. 커밋 메세지 변경을 위한 revert --- src/main/kotlin/racingcar/Application.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index d81dd12d..4778d4ed 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -24,14 +24,6 @@ fun main() { println("$key : " + "-".repeat(carMap[key]!!)) } - println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 println() } - - // TODO: 함수 분리할 것 - println( - "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } - .keys - .joinToString(", "), - ) } From 26ac6c33e8e124e732ddb3634fa1f22d4158597d Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:16:23 +0900 Subject: [PATCH 12/43] =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 우승자는 한 명 이상일 수 있음 - 쉼표(,)로 우승자 여러 명 출력 --- src/main/kotlin/racingcar/Application.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 4778d4ed..7513bd0c 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -24,6 +24,14 @@ fun main() { println("$key : " + "-".repeat(carMap[key]!!)) } + println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 println() } + + // TODO: 함수 분리할 것 + println( + "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } + .keys + .joinToString(", ") + ) } From c08ac6afff23d7f62e1b48530635446e588fb2af Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:17:42 +0900 Subject: [PATCH 13/43] =?UTF-8?q?Revert=20"=EC=9A=B0=EC=8A=B9=EC=9E=90=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 26ac6c33e8e124e732ddb3634fa1f22d4158597d. 커밋 컨벤션이 적용되지 않았으므로 다시 revert --- src/main/kotlin/racingcar/Application.kt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 7513bd0c..4778d4ed 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -24,14 +24,6 @@ fun main() { println("$key : " + "-".repeat(carMap[key]!!)) } - println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 println() } - - // TODO: 함수 분리할 것 - println( - "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } - .keys - .joinToString(", ") - ) } From 7fbd96111ea2590ed46581b9dfc655f0f9b5a18a Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:23:06 +0900 Subject: [PATCH 14/43] =?UTF-8?q?feat:=20=EC=9A=B0=EC=8A=B9=EC=9E=90=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 우승자는 한 명 이상일 수 있음 - 쉼표(,)로 우승자 여러 명 출력 --- src/main/kotlin/racingcar/Application.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 4778d4ed..7513bd0c 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -24,6 +24,14 @@ fun main() { println("$key : " + "-".repeat(carMap[key]!!)) } + println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 println() } + + // TODO: 함수 분리할 것 + println( + "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } + .keys + .joinToString(", ") + ) } From 459bf630a44c918db079b751ec1964040c48ee85 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:29:00 +0900 Subject: [PATCH 15/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=EC=9D=98=20for=EB=AC=B8=20=EC=9D=98=20i=20->=20carNam?= =?UTF-8?q?e=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 7513bd0c..0459a2aa 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -8,8 +8,8 @@ fun main() { println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") // TODO : trim() ? 으로 공백 제거? // 커밋 body에 올렸다 PR 설명에 적기 - for (i in readLine().split(",")) { - carMap.put(i, 0) + for (carName in readLine().split(",")) { + carMap.put(carName, 0) } println("시도할 횟수는 몇 회인가요?") From 2ff21778fab97ae28fcf4ff6f77f33c181bd135d Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:50:58 +0900 Subject: [PATCH 16/43] =?UTF-8?q?feat:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EA=B0=92=EC=97=90=20=EB=8C=80=ED=95=B4=20Ill?= =?UTF-8?q?egalArgumentException=20=EB=B0=9C=EC=83=9D=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 자동차 각각의 이름은 5자 이하 --- src/main/kotlin/racingcar/Application.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0459a2aa..e109eee9 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -9,6 +9,7 @@ fun main() { println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") // TODO : trim() ? 으로 공백 제거? // 커밋 body에 올렸다 PR 설명에 적기 for (carName in readLine().split(",")) { + require(carName.length <= 5) { "자동차 이름은 5자 이하만 가능하다." } // TODO: 조건식 변수화 carMap.put(carName, 0) } From 0fa3033b8bc707410aa19659aed7032ca920bdbc Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:03:36 +0900 Subject: [PATCH 17/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index e109eee9..2718d105 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -6,7 +6,7 @@ import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange fun main() { val carMap = mutableMapOf() - println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + promptForCarNames() // TODO : trim() ? 으로 공백 제거? // 커밋 body에 올렸다 PR 설명에 적기 for (carName in readLine().split(",")) { require(carName.length <= 5) { "자동차 이름은 5자 이하만 가능하다." } // TODO: 조건식 변수화 @@ -36,3 +36,7 @@ fun main() { .joinToString(", ") ) } + +fun promptForCarNames() { + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") +} From df5a4f8845b2cf8fecb1990af054affc5b5ded18 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:09:28 +0900 Subject: [PATCH 18/43] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EC=A4=91=EC=9D=98=20?= =?UTF-8?q?=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 2718d105..c3f3dc39 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -7,8 +7,8 @@ fun main() { val carMap = mutableMapOf() promptForCarNames() - // TODO : trim() ? 으로 공백 제거? // 커밋 body에 올렸다 PR 설명에 적기 - for (carName in readLine().split(",")) { + + for (carName in readLine().split(",").map { it.trim() }) { require(carName.length <= 5) { "자동차 이름은 5자 이하만 가능하다." } // TODO: 조건식 변수화 carMap.put(carName, 0) } From 2992cc85c9d8dc3b74715f5f6e763bc2f2e68ab9 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:10:57 +0900 Subject: [PATCH 19/43] =?UTF-8?q?style:=20kotlin=20style=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EA=B3=B5=EB=B0=B1=20=EB=88=84=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index c3f3dc39..8ced429a 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -19,7 +19,7 @@ fun main() { println("실행 결과") for (i in 0 until attemptNumber) { carMap.forEach { key, value -> - if (pickNumberInRange(0,9) >= 4) { + if (pickNumberInRange(0, 9) >= 4) { carMap[key] = value + 1 } From 32a34c98c7553d12e113b975df248566cad4d33a Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:14:32 +0900 Subject: [PATCH 20/43] =?UTF-8?q?style:=20=EC=8B=9D=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 8ced429a..9b3799d4 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -37,6 +37,4 @@ fun main() { ) } -fun promptForCarNames() { - println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") -} +fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") From f349145ed0da570ea991296d45fb1fd820ef9ebe Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:29:08 +0900 Subject: [PATCH 21/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=EA=B0=92=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ,기준 문자열 분할 - 공백 제거 --- src/main/kotlin/racingcar/Application.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 9b3799d4..0819b015 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -8,7 +8,7 @@ fun main() { promptForCarNames() - for (carName in readLine().split(",").map { it.trim() }) { + for (carName in processCarNames(readLine())) { require(carName.length <= 5) { "자동차 이름은 5자 이하만 가능하다." } // TODO: 조건식 변수화 carMap.put(carName, 0) } @@ -38,3 +38,6 @@ fun main() { } fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + +fun processCarNames(input: String) = input.split(",") + .map { it.trim() } \ No newline at end of file From 7c62c2b659670ab5084714e70846037e3c645de7 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:06:57 +0900 Subject: [PATCH 22/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0819b015..37db430c 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -3,13 +3,15 @@ package racingcar import camp.nextstep.edu.missionutils.Console.readLine import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange +val isCarNameValidLength = { carName: String -> carName.length <= 5 } + fun main() { val carMap = mutableMapOf() promptForCarNames() for (carName in processCarNames(readLine())) { - require(carName.length <= 5) { "자동차 이름은 5자 이하만 가능하다." } // TODO: 조건식 변수화 + validateCarName(carName) carMap.put(carName, 0) } @@ -40,4 +42,8 @@ fun main() { fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") fun processCarNames(input: String) = input.split(",") - .map { it.trim() } \ No newline at end of file + .map { it.trim() } + +fun validateCarName(carName: String) { + require(isCarNameValidLength(carName)) { "자동차 이름은 5자 이하만 가능하다." } +} \ No newline at end of file From 10eef296591e604b22932db855a5fce103efbea7 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:24:50 +0900 Subject: [PATCH 23/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?map=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=9E=91=EC=97=85=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 37db430c..1158feb0 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -9,11 +9,7 @@ fun main() { val carMap = mutableMapOf() promptForCarNames() - - for (carName in processCarNames(readLine())) { - validateCarName(carName) - carMap.put(carName, 0) - } + initializeCarMap(carMap, processCarNames(readLine())) println("시도할 횟수는 몇 회인가요?") val attemptNumber = readLine().toInt() // TODO : 위치 변경? @@ -44,6 +40,13 @@ fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요 fun processCarNames(input: String) = input.split(",") .map { it.trim() } +fun initializeCarMap(carMap: MutableMap, carList: List) { + for (carName in carList) { + validateCarName(carName) + carMap.put(carName, 0) + } +} + fun validateCarName(carName: String) { require(isCarNameValidLength(carName)) { "자동차 이름은 5자 이하만 가능하다." } } \ No newline at end of file From a63dbf1bb9ae918705b4546c6c88a8da2ec22d2a Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:27:53 +0900 Subject: [PATCH 24/43] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=8F=99=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=9A=94=EC=B2=AD=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 1158feb0..798e4c02 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -11,7 +11,7 @@ fun main() { promptForCarNames() initializeCarMap(carMap, processCarNames(readLine())) - println("시도할 횟수는 몇 회인가요?") + promptForAttemptNumber() val attemptNumber = readLine().toInt() // TODO : 위치 변경? println("실행 결과") @@ -36,6 +36,7 @@ fun main() { } fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") +fun promptForAttemptNumber() = println("시도할 횟수는 몇 회인가요?") fun processCarNames(input: String) = input.split(",") .map { it.trim() } From f245451d30d04e2a9ff4cbebfbd165705fa3bf26 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:33:06 +0900 Subject: [PATCH 25/43] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=8F=99=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=EA=B0=92=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=95=A8=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 798e4c02..4cf0a747 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -12,7 +12,7 @@ fun main() { initializeCarMap(carMap, processCarNames(readLine())) promptForAttemptNumber() - val attemptNumber = readLine().toInt() // TODO : 위치 변경? + val attemptNumber = processAttemptNumber(readLine()) println("실행 결과") for (i in 0 until attemptNumber) { @@ -41,6 +41,8 @@ fun promptForAttemptNumber() = println("시도할 횟수는 몇 회인가요?") fun processCarNames(input: String) = input.split(",") .map { it.trim() } +fun processAttemptNumber(input: String) = input.toInt() + fun initializeCarMap(carMap: MutableMap, carList: List) { for (carName in carList) { validateCarName(carName) From 9dd5110b65633f95b304729caac8a0b88535669d Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:44:46 +0900 Subject: [PATCH 26/43] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=EA=B0=92=EC=9D=84=20?= =?UTF-8?q?map=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=9E=91=EC=97=85=20=EB=B6=84=ED=95=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit carMap의 선언을 함수 실행과 일치시켰으며 인자로 자동차 이름을 처리하는 과정을 새로운 코드로 내보냈습니다. --- src/main/kotlin/racingcar/Application.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 4cf0a747..80c5b648 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -6,10 +6,10 @@ import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange val isCarNameValidLength = { carName: String -> carName.length <= 5 } fun main() { - val carMap = mutableMapOf() promptForCarNames() - initializeCarMap(carMap, processCarNames(readLine())) + val carList = processCarNames(readLine()) + val carMap = initializeCarMap(carList) promptForAttemptNumber() val attemptNumber = processAttemptNumber(readLine()) @@ -43,11 +43,15 @@ fun processCarNames(input: String) = input.split(",") fun processAttemptNumber(input: String) = input.toInt() -fun initializeCarMap(carMap: MutableMap, carList: List) { +fun initializeCarMap(carList: List): MutableMap { + val carMap = mutableMapOf() + for (carName in carList) { validateCarName(carName) carMap.put(carName, 0) } + + return carMap } fun validateCarName(carName: String) { From 5936a823ddf24e030c49e03449856fda867940f7 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:12:24 +0900 Subject: [PATCH 27/43] =?UTF-8?q?refactor:=20=EB=AC=B4=EC=9E=91=EC=9C=84?= =?UTF-8?q?=20=EA=B0=92=EC=9D=84=20=EB=BD=91=EC=95=84=20=EC=A0=84=EC=A7=84?= =?UTF-8?q?=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20=EA=B2=80=EC=82=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=9E=91=EC=97=85=20=EB=B3=80=EC=88=98=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 80c5b648..0519c153 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -4,6 +4,7 @@ import camp.nextstep.edu.missionutils.Console.readLine import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange val isCarNameValidLength = { carName: String -> carName.length <= 5 } +val isMoveForwardValid = { pickNumberInRange(0, 9) >= 4 } fun main() { @@ -17,7 +18,7 @@ fun main() { println("실행 결과") for (i in 0 until attemptNumber) { carMap.forEach { key, value -> - if (pickNumberInRange(0, 9) >= 4) { + if (isMoveForwardValid()) { carMap[key] = value + 1 } From 2f7d228bc2b33eb345210337b30fb3142e30e964 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:30:14 +0900 Subject: [PATCH 28/43] =?UTF-8?q?refactor:=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EC=8B=A4=ED=96=89=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=9E=91=EC=97=85=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - moveForwardIfVaild() : 전진 조건에 따라 전진 - printRaceResult() : 각 실행 별 전진 출력 - printAllRaceResults() : 모든 실행 출력 --- src/main/kotlin/racingcar/Application.kt | 37 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0519c153..675bca9e 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -2,6 +2,7 @@ package racingcar import camp.nextstep.edu.missionutils.Console.readLine import camp.nextstep.edu.missionutils.Randoms.pickNumberInRange +import kotlin.collections.set val isCarNameValidLength = { carName: String -> carName.length <= 5 } val isMoveForwardValid = { pickNumberInRange(0, 9) >= 4 } @@ -15,18 +16,7 @@ fun main() { promptForAttemptNumber() val attemptNumber = processAttemptNumber(readLine()) - println("실행 결과") - for (i in 0 until attemptNumber) { - carMap.forEach { key, value -> - if (isMoveForwardValid()) { - carMap[key] = value + 1 - } - - println("$key : " + "-".repeat(carMap[key]!!)) - } - println(carMap) // TODO : 테스트용 출력 ; 삭제할 것 - println() - } + printAllRaceResults(carMap, attemptNumber) // TODO: 함수 분리할 것 println( @@ -55,6 +45,29 @@ fun initializeCarMap(carList: List): MutableMap { return carMap } +fun printAllRaceResults(carMap: MutableMap, attemptNumber: Int) { + println("실행 결과") + + for (i in 0 until attemptNumber) { + printRaceResult(carMap) + println() + } +} + +fun printRaceResult(carMap: MutableMap) { + carMap.forEach { key, value -> + moveForwardIfVaild(carMap, key, value) + + println("$key : " + "-".repeat(carMap[key]!!)) + } +} + +fun moveForwardIfVaild(carMap: MutableMap, key: String, value: Int) { + if (isMoveForwardValid()) { + carMap[key] = value + 1 + } +} + fun validateCarName(carName: String) { require(isCarNameValidLength(carName)) { "자동차 이름은 5자 이하만 가능하다." } } \ No newline at end of file From 96d9ce11610c00dde31b02eddfee8203a7d10c86 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:49:46 +0900 Subject: [PATCH 29/43] =?UTF-8?q?refactor:=20=EC=9A=B0=EC=8A=B9=EC=9E=90?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5=20=EC=9E=91=EC=97=85=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ilterWinners() : 우승자 선별 - printWinners() : 모든 우승자 출력 --- src/main/kotlin/racingcar/Application.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 675bca9e..7c9983c8 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -6,6 +6,7 @@ import kotlin.collections.set val isCarNameValidLength = { carName: String -> carName.length <= 5 } val isMoveForwardValid = { pickNumberInRange(0, 9) >= 4 } +val isWinnerValid = { carMap: MutableMap, count: Int -> count == carMap.values.maxOrNull() } fun main() { @@ -18,12 +19,7 @@ fun main() { printAllRaceResults(carMap, attemptNumber) - // TODO: 함수 분리할 것 - println( - "최종 우승자 : " + carMap.filterValues { it == carMap.values.maxOrNull() } - .keys - .joinToString(", ") - ) + printWinners(carMap) } fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") @@ -68,6 +64,12 @@ fun moveForwardIfVaild(carMap: MutableMap, key: String, value: Int) } } +fun printWinners(carMap: MutableMap) = println( + "최종 우승자 : " + filterWinners(carMap).joinToString(", ") +) + +fun filterWinners(carMap: MutableMap) = carMap.filterValues { isWinnerValid(carMap, it) }.keys + fun validateCarName(carName: String) { require(isCarNameValidLength(carName)) { "자동차 이름은 5자 이하만 가능하다." } } \ No newline at end of file From efa2cb0abc414ac52b0adcce406988e066535174 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 20:58:23 +0900 Subject: [PATCH 30/43] =?UTF-8?q?refactor(processCarNames()):=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=B4=20return=20typ?= =?UTF-8?q?e=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 7c9983c8..44536883 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -25,7 +25,7 @@ fun main() { fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") fun promptForAttemptNumber() = println("시도할 횟수는 몇 회인가요?") -fun processCarNames(input: String) = input.split(",") +fun processCarNames(input: String): List = input.split(",") .map { it.trim() } fun processAttemptNumber(input: String) = input.toInt() From 281d940ceb7b870aa6ae5f5418ef00880e29c59c Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:28:21 +0900 Subject: [PATCH 31/43] =?UTF-8?q?refactor:=20Strings=20string=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=83=81=EC=88=98=20=ED=8C=8C=EC=9D=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EB=B0=8F=20Application.kt=20=EB=82=B4=20string=20?= =?UTF-8?q?=EA=B5=90=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 Constants에서 Strings로 파일명 교체했습니다. --- src/main/kotlin/racingcar/Application.kt | 10 +++++----- src/main/kotlin/racingcar/Constants.kt | 6 ------ src/main/kotlin/racingcar/Strings.kt | 9 +++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 src/main/kotlin/racingcar/Constants.kt create mode 100644 src/main/kotlin/racingcar/Strings.kt diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 44536883..20e7cc4f 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -22,8 +22,8 @@ fun main() { printWinners(carMap) } -fun promptForCarNames() = println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") -fun promptForAttemptNumber() = println("시도할 횟수는 몇 회인가요?") +fun promptForCarNames() = println(Strings.MESSAGE_INPUT_CAR_NAME) +fun promptForAttemptNumber() = println(Strings.MESSAGE_INPUT_ATTEMPT_NUMBER) fun processCarNames(input: String): List = input.split(",") .map { it.trim() } @@ -42,7 +42,7 @@ fun initializeCarMap(carList: List): MutableMap { } fun printAllRaceResults(carMap: MutableMap, attemptNumber: Int) { - println("실행 결과") + println(Strings.MESSAGE_OUTPUT_RESULT) for (i in 0 until attemptNumber) { printRaceResult(carMap) @@ -65,11 +65,11 @@ fun moveForwardIfVaild(carMap: MutableMap, key: String, value: Int) } fun printWinners(carMap: MutableMap) = println( - "최종 우승자 : " + filterWinners(carMap).joinToString(", ") + Strings.MESSAGE_OUTPUT_WINNER + filterWinners(carMap).joinToString(", ") ) fun filterWinners(carMap: MutableMap) = carMap.filterValues { isWinnerValid(carMap, it) }.keys fun validateCarName(carName: String) { - require(isCarNameValidLength(carName)) { "자동차 이름은 5자 이하만 가능하다." } + require(isCarNameValidLength(carName)) { Strings.MESSAGE_EXCEPTION_CAR_NAME_LENGTH } } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/Constants.kt b/src/main/kotlin/racingcar/Constants.kt deleted file mode 100644 index c832afb1..00000000 --- a/src/main/kotlin/racingcar/Constants.kt +++ /dev/null @@ -1,6 +0,0 @@ -package racingcar - -object Constants { - const val MESSAGE_INPUT_CAR_NAME = "경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)" - const val MESSAGE_INPUT_ATTEMPT_NUMBER = "시도할 횟수는 몇 회인가요?" -} \ No newline at end of file diff --git a/src/main/kotlin/racingcar/Strings.kt b/src/main/kotlin/racingcar/Strings.kt new file mode 100644 index 00000000..4a322da4 --- /dev/null +++ b/src/main/kotlin/racingcar/Strings.kt @@ -0,0 +1,9 @@ +package racingcar + +object Strings { + const val MESSAGE_INPUT_CAR_NAME = "경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)" + const val MESSAGE_INPUT_ATTEMPT_NUMBER = "시도할 횟수는 몇 회인가요?" + const val MESSAGE_OUTPUT_RESULT = "실행 결과" + const val MESSAGE_OUTPUT_WINNER = "최종 우승자 : " + const val MESSAGE_EXCEPTION_CAR_NAME_LENGTH = "자동차 이름은 5자 이하만 가능합니다." +} \ No newline at end of file From 17eb0418983043fc35abb84713500bb90e10041b Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:50:58 +0900 Subject: [PATCH 32/43] =?UTF-8?q?test:=20=EC=98=88=EC=99=B8=EC=9D=98=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=EC=A0=81=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 3c601c8e..27a4bcb1 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -22,7 +22,9 @@ class ApplicationTest : NsTest() { @Test fun `예외 테스트`() { assertSimpleTest { - assertThrows { runException("pobi,javaji", "1") } + val exception = assertThrows { runException("pobi,javaji", "1") } + + exception.printStackTrace() } } From 26c033bf1366bc6487423536a5251ef580eb2364 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:00:12 +0900 Subject: [PATCH 33/43] =?UTF-8?q?test:=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=203=EB=AA=85=20=EC=9D=B4=EC=83=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 27a4bcb1..73ee4279 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -19,6 +19,17 @@ class ApplicationTest : NsTest() { ) } + @Test + fun `기능 테스트 3명 이상`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni,jun", "5") + assertThat(output()).contains("pobi : -", "woni : ", "jun : ", "최종 우승자 : pobi") + }, + MOVING_FORWARD, STOP + ) + } + @Test fun `예외 테스트`() { assertSimpleTest { From 248f8d83af391d34a1648f932fc9a65766fe8f32 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:02:50 +0900 Subject: [PATCH 34/43] =?UTF-8?q?test:=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=202=EB=AA=85=20=EC=9D=B4=EC=83=81=EC=9D=98?= =?UTF-8?q?=20=EC=9A=B0=EC=8A=B9=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 73ee4279..7c8255d9 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -30,6 +30,24 @@ class ApplicationTest : NsTest() { ) } + @Test + fun `기능 테스트 2명 이상의 우승자`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni,jun,a,b", "3") + assertThat(output()).contains( + "pobi : -", + "woni : ", + "jun : ", + "a : ", + "b : ", + "최종 우승자 : pobi, woni, jun, a, b" + ) + }, + MOVING_FORWARD + ) + } + @Test fun `예외 테스트`() { assertSimpleTest { From bd7dc92a95f863693f65df21e95f8b8f33978e4b Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:04:47 +0900 Subject: [PATCH 35/43] =?UTF-8?q?test:=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 7c8255d9..fc7bd928 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -48,6 +48,22 @@ class ApplicationTest : NsTest() { ) } + @Test + fun `기능 테스트 공백 제거`() { + assertRandomNumberInRangeTest( + { + run(" a , b , c", "3") + assertThat(output()).contains( + "a : -", + "b : -", + "c : -", + "최종 우승자 : a, b, c" + ) + }, + MOVING_FORWARD + ) + } + @Test fun `예외 테스트`() { assertSimpleTest { From db19f398b8e5eff920ed6cef5f94895b2a6c8716 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:10:34 +0900 Subject: [PATCH 36/43] =?UTF-8?q?refactor:=20typo=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 20e7cc4f..57b54648 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -52,13 +52,13 @@ fun printAllRaceResults(carMap: MutableMap, attemptNumber: Int) { fun printRaceResult(carMap: MutableMap) { carMap.forEach { key, value -> - moveForwardIfVaild(carMap, key, value) + moveForwardIfValid(carMap, key, value) println("$key : " + "-".repeat(carMap[key]!!)) } } -fun moveForwardIfVaild(carMap: MutableMap, key: String, value: Int) { +fun moveForwardIfValid(carMap: MutableMap, key: String, value: Int) { if (isMoveForwardValid()) { carMap[key] = value + 1 } From a526ae6ecefc3c0e7a2af63a7ac8e381baf96fd4 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:14:42 +0900 Subject: [PATCH 37/43] =?UTF-8?q?test:=20=EB=8B=A8=EC=9C=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index fc7bd928..75d8bd99 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -64,6 +64,14 @@ class ApplicationTest : NsTest() { ) } + @Test + fun `단위 테스트 공백 제거`() { + val input = " tesla , audi , bmw " + val result = processCarNames(input) + + assertThat(result).containsExactly("tesla", "audi", "bmw") + } + @Test fun `예외 테스트`() { assertSimpleTest { From 88019d02d76224a5a37e164eaea26a49fd3aeff6 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:23:18 +0900 Subject: [PATCH 38/43] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 4 +++- src/main/kotlin/racingcar/Strings.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 57b54648..1bf4dcde 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -28,7 +28,9 @@ fun promptForAttemptNumber() = println(Strings.MESSAGE_INPUT_ATTEMPT_NUMBER) fun processCarNames(input: String): List = input.split(",") .map { it.trim() } -fun processAttemptNumber(input: String) = input.toInt() +fun processAttemptNumber(input: String) = + input.toIntOrNull() ?: throw IllegalArgumentException(Strings.MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER) + fun initializeCarMap(carList: List): MutableMap { val carMap = mutableMapOf() diff --git a/src/main/kotlin/racingcar/Strings.kt b/src/main/kotlin/racingcar/Strings.kt index 4a322da4..93d5348a 100644 --- a/src/main/kotlin/racingcar/Strings.kt +++ b/src/main/kotlin/racingcar/Strings.kt @@ -6,4 +6,5 @@ object Strings { const val MESSAGE_OUTPUT_RESULT = "실행 결과" const val MESSAGE_OUTPUT_WINNER = "최종 우승자 : " const val MESSAGE_EXCEPTION_CAR_NAME_LENGTH = "자동차 이름은 5자 이하만 가능합니다." + const val MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER = "입력 횟수는 정수값이여야 합니다." } \ No newline at end of file From 10ede80088ef4915cec648e9debd9bc0dccf9fdc Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:35:30 +0900 Subject: [PATCH 39/43] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 7 +++++-- src/main/kotlin/racingcar/Strings.kt | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 1bf4dcde..e3d036bb 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -25,8 +25,11 @@ fun main() { fun promptForCarNames() = println(Strings.MESSAGE_INPUT_CAR_NAME) fun promptForAttemptNumber() = println(Strings.MESSAGE_INPUT_ATTEMPT_NUMBER) -fun processCarNames(input: String): List = input.split(",") - .map { it.trim() } +fun processCarNames(input: String): List { + val carList = input.split(",").map { it.trim() } + require(carList.all { it.isNotBlank() }) { Strings.MESSAGE_EXCEPTION_INPUT_CAR_NAMES } + return carList +} fun processAttemptNumber(input: String) = input.toIntOrNull() ?: throw IllegalArgumentException(Strings.MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER) diff --git a/src/main/kotlin/racingcar/Strings.kt b/src/main/kotlin/racingcar/Strings.kt index 93d5348a..27609fba 100644 --- a/src/main/kotlin/racingcar/Strings.kt +++ b/src/main/kotlin/racingcar/Strings.kt @@ -6,5 +6,6 @@ object Strings { const val MESSAGE_OUTPUT_RESULT = "실행 결과" const val MESSAGE_OUTPUT_WINNER = "최종 우승자 : " const val MESSAGE_EXCEPTION_CAR_NAME_LENGTH = "자동차 이름은 5자 이하만 가능합니다." + const val MESSAGE_EXCEPTION_INPUT_CAR_NAMES = "자동차 이름은 값이 없거나 공백이 아니여야 합니다." const val MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER = "입력 횟수는 정수값이여야 합니다." } \ No newline at end of file From 81b0953b3b4deec7ca09d44dab3e74581610cfb5 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:37:44 +0900 Subject: [PATCH 40/43] =?UTF-8?q?style:=20=EC=9E=85=EB=A0=A5=20=ED=9A=9F?= =?UTF-8?q?=EC=88=98=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=8A=A4=ED=83=80=EC=9D=BC=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index e3d036bb..38bbc9c0 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -31,8 +31,10 @@ fun processCarNames(input: String): List { return carList } -fun processAttemptNumber(input: String) = - input.toIntOrNull() ?: throw IllegalArgumentException(Strings.MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER) +fun processAttemptNumber(input: String): Int { + require(input.toIntOrNull() != null) { Strings.MESSAGE_EXCEPTION_INPUT_ATTEMPT_NUMBER } + return input.toInt() +} fun initializeCarMap(carList: List): MutableMap { From b8f2f72dc8aa55e89c7c3e1712b3690bce0c6987 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:39:05 +0900 Subject: [PATCH 41/43] =?UTF-8?q?refactor(test):=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20->=20=ED=86=B5=ED=95=A9=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A1=9C=20=EB=AA=85=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 75d8bd99..b9b2e54c 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -9,7 +9,7 @@ import org.junit.jupiter.api.assertThrows class ApplicationTest : NsTest() { @Test - fun `기능 테스트`() { + fun `통합 테스트`() { assertRandomNumberInRangeTest( { run("pobi,woni", "1") @@ -20,7 +20,7 @@ class ApplicationTest : NsTest() { } @Test - fun `기능 테스트 3명 이상`() { + fun `통합 테스트 3명 이상`() { assertRandomNumberInRangeTest( { run("pobi,woni,jun", "5") @@ -31,7 +31,7 @@ class ApplicationTest : NsTest() { } @Test - fun `기능 테스트 2명 이상의 우승자`() { + fun `통합 테스트 2명 이상의 우승자`() { assertRandomNumberInRangeTest( { run("pobi,woni,jun,a,b", "3") @@ -49,7 +49,7 @@ class ApplicationTest : NsTest() { } @Test - fun `기능 테스트 공백 제거`() { + fun `통합 테스트 공백 제거`() { assertRandomNumberInRangeTest( { run(" a , b , c", "3") From abd8407d32c9f46445481aa325262638a94848cb Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:40:12 +0900 Subject: [PATCH 42/43] =?UTF-8?q?refactor(test):=20=EC=9D=98=EB=AF=B8?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=EB=81=94=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index b9b2e54c..c7e5f8e1 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -73,7 +73,7 @@ class ApplicationTest : NsTest() { } @Test - fun `예외 테스트`() { + fun `예외 테스트 자동차 이름 5자 초과`() { assertSimpleTest { val exception = assertThrows { runException("pobi,javaji", "1") } From 8bee7c65774174af71a4bd0623449ff47fb9f0b3 Mon Sep 17 00:00:00 2001 From: HyunjeLee <101737272+HyunjeLee@users.noreply.github.com> Date: Mon, 28 Oct 2024 22:41:24 +0900 Subject: [PATCH 43/43] =?UTF-8?q?test:=20=EC=98=88=EC=99=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B3=B5=EB=B0=B1=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A4=84=EC=A7=84=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/racingcar/ApplicationTest.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index c7e5f8e1..2f28e393 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -81,6 +81,15 @@ class ApplicationTest : NsTest() { } } + @Test + fun `예외 테스트 공백으로 이뤄진 자동차 이름`() { + assertSimpleTest { + val exception = assertThrows { runException(" , ,", "1") } + + exception.printStackTrace() + } + } + override fun runMain() { main() }