From e3138f787cdacd6cbb70d77ff62bcd621c0f36e9 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 19:57:48 +0900 Subject: [PATCH 1/9] =?UTF-8?q?docs=20(README.md):=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 구현에 앞서 어떤 기능을 구현할지 정리 - 도메인 구현 - 출력 부분 - 입력 부분 - 기능 부분 README.md 하단에 기능 목록이 추가 되었습니다. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 43803e204..65eb5e4a2 100644 --- a/README.md +++ b/README.md @@ -159,3 +159,13 @@ Randoms.pickNumberInRange(0, 9) - **Git의 커밋 단위는 앞 단계에서 `docs/README.md`에 정리한 기능 목록 단위**로 추가한다. - [커밋 메시지 컨벤션](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) 가이드를 참고해 커밋 메시지를 작성한다. - 과제 진행 및 제출 방법은 [프리코스 과제 제출](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) 문서를 참고한다. + +## 기능 목록 + +- Player 도메인 구현하기 +- 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 +- 기본적인 게임을 제공할 틀 만들기 +- 사용자로부터 입력을 받을 수 있는 기능 만들기 +- 받은 값을 저장할 수 있도록 기능 만들기 +- 실제 게임을 진행하는 기능 만들기 +- 게임이 다 끝난 후 출력 만들기 \ No newline at end of file From 3bb907b3e7cf893397c6a5a9137dbb01eedd3c42 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:01:27 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat=20(Player.class):=20=ED=94=8C=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 플레이어 도메인 추가 및 README.md 업데이트 - 플레이어 이름 - 승리 카운트 - README.md 에 도메인 구현 부분 clear 표시 추가 플레이어에게 필요한 기능만을 추가한 플레이어 도메인이 추가되었습니다. 이름을 저장할 name과 승리 횟수를 저장할 count로 구성되어 있습니다. --- README.md | 2 +- src/main/kotlin/domain/Player.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/domain/Player.kt diff --git a/README.md b/README.md index 65eb5e4a2..e7d460b44 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Randoms.pickNumberInRange(0, 9) ## 기능 목록 -- Player 도메인 구현하기 +- Player 도메인 구현하기 v - 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 - 기본적인 게임을 제공할 틀 만들기 - 사용자로부터 입력을 받을 수 있는 기능 만들기 diff --git a/src/main/kotlin/domain/Player.kt b/src/main/kotlin/domain/Player.kt new file mode 100644 index 000000000..6509f5312 --- /dev/null +++ b/src/main/kotlin/domain/Player.kt @@ -0,0 +1,12 @@ +package domain +data class Player( + val name: String, + var winCount: Int = 0 +) { + fun addWinCount() { + winCount++ + } + companion object { + fun toPlayer(name: String): Player = Player(name, 0) + } +} From b776953b52d37dea5b2ecabe03bec6e22984d2a9 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:08:55 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat=20(PrintGame):=20print=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EA=B3=BC=20ReadMe.md=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit print를 위한 인터페이스 및 클래스 구현 - 시작, 끝, 게임 도중으로 나누어 인터페이스 구현 - 인터페이스에 맞게 클래스 구현 - README.md 에 사용자에게 보여주는 부분 clear 표시 추가 사용자에게 게임 상태를 보여주기 위한 클래스가 추가되었습니다. --- README.md | 2 +- src/main/kotlin/service/CarPrintGame.kt | 31 +++++++++++++++++++++++++ src/main/kotlin/service/PrintGame.kt | 12 ++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/service/CarPrintGame.kt create mode 100644 src/main/kotlin/service/PrintGame.kt diff --git a/README.md b/README.md index e7d460b44..2ab538c08 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ Randoms.pickNumberInRange(0, 9) ## 기능 목록 - Player 도메인 구현하기 v -- 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 +- 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 v - 기본적인 게임을 제공할 틀 만들기 - 사용자로부터 입력을 받을 수 있는 기능 만들기 - 받은 값을 저장할 수 있도록 기능 만들기 diff --git a/src/main/kotlin/service/CarPrintGame.kt b/src/main/kotlin/service/CarPrintGame.kt new file mode 100644 index 000000000..cef756506 --- /dev/null +++ b/src/main/kotlin/service/CarPrintGame.kt @@ -0,0 +1,31 @@ +package racingcar.servie + +import service.PrintGame + + +class CarPrintGame : PrintGame { + override fun printInit() { + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + } + + override fun tryCount() { + println("시도할 횟수는 몇 회인가요?") + } + + override fun printGame(playerName: String, goCount: Int) { + print("$playerName : ") + for (loop in 0..) { + print("최종 우승자 : ") + //마지막에서 한명을 제외하고 ", " 형식으로 뽑기위해서 -2를 사용한다 + for (loop in 0..) +} \ No newline at end of file From 9d0d675c7a0dfe2f2131be0c1789ca13f4a0278b Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:14:24 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat=20(PlayGame):=20gamePlay=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20ReadMe=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=81=ED=83=9C=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 인터페이스 구현 및 ReadMe 파일 상태 업데이트 - 게임 시작, 끝, 진행을 위한 인터페이스 구현 - ReadMe.md 파일에 상태 업데이트 게임 플레이를 구현하기 위해 필요한 인터페이스 틀을 구현하였습니다. --- README.md | 2 +- src/main/kotlin/service/PlayGame.kt | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/service/PlayGame.kt diff --git a/README.md b/README.md index 2ab538c08..e519192c7 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ Randoms.pickNumberInRange(0, 9) - Player 도메인 구현하기 v - 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 v -- 기본적인 게임을 제공할 틀 만들기 +- 기본적인 게임을 제공할 틀 만들기 v - 사용자로부터 입력을 받을 수 있는 기능 만들기 - 받은 값을 저장할 수 있도록 기능 만들기 - 실제 게임을 진행하는 기능 만들기 diff --git a/src/main/kotlin/service/PlayGame.kt b/src/main/kotlin/service/PlayGame.kt new file mode 100644 index 000000000..7cdcbbb16 --- /dev/null +++ b/src/main/kotlin/service/PlayGame.kt @@ -0,0 +1,14 @@ +package service + +interface PlayGame { + // 게임 셋팅 + fun initGame() + // 플레이어 값 초기화 + fun initPlayers(names: List) + // 게임의 전체 진행을 위한 메서드 + fun playGame() + // 게임의 각 라운드를 위한 메서드 + fun playRound() + // 게임 종료시 호출될 메서드 + fun endGame(winnerCount: Int) +} \ No newline at end of file From 6258a85a7ebf63f04227454b019a18bedd48a045 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:24:49 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat=20(CarPlayGameImpl):=20playGame?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=9D=BC=EB=B6=80=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=EA=B3=BC=20=EC=9E=98=EB=AA=BB?= =?UTF-8?q?=EB=90=9C=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20readMe=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit playGame을 위한 일부 기능 구현과 잘못된 패키지 구조 변경 - 사용자로부터 입력 받을 수 있는 기능 개발 - 입력받은 값 셋팅할 수 있도록 개발 - service, domain racingCar 하위로 변경 - readMe 상태 update 게임 플레이를 위한 사용자 입력과 그 값을 setting 할 수 있는 부분 구현 되었습니다. 패키지 구조가 이상하여 racingCar 하위로 service, domain을 이동하였습니다. --- README.md | 4 +- .../kotlin/{ => racingcar}/domain/Player.kt | 3 +- .../racingcar/service/CarPlayGameImpl.kt | 42 +++++++++++++++++++ .../{ => racingcar}/service/CarPrintGame.kt | 4 +- .../{ => racingcar}/service/PlayGame.kt | 2 +- .../{ => racingcar}/service/PrintGame.kt | 2 +- 6 files changed, 49 insertions(+), 8 deletions(-) rename src/main/kotlin/{ => racingcar}/domain/Player.kt (89%) create mode 100644 src/main/kotlin/racingcar/service/CarPlayGameImpl.kt rename src/main/kotlin/{ => racingcar}/service/CarPrintGame.kt (93%) rename src/main/kotlin/{ => racingcar}/service/PlayGame.kt (93%) rename src/main/kotlin/{ => racingcar}/service/PrintGame.kt (93%) diff --git a/README.md b/README.md index e519192c7..439cca858 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ Randoms.pickNumberInRange(0, 9) - Player 도메인 구현하기 v - 사용자에게 보여주는 기능을 할 printGame 부분 구현하기 v - 기본적인 게임을 제공할 틀 만들기 v -- 사용자로부터 입력을 받을 수 있는 기능 만들기 -- 받은 값을 저장할 수 있도록 기능 만들기 +- 사용자로부터 입력을 받을 수 있는 기능 만들기 v +- 받은 값을 저장할 수 있도록 기능 만들기 v - 실제 게임을 진행하는 기능 만들기 - 게임이 다 끝난 후 출력 만들기 \ No newline at end of file diff --git a/src/main/kotlin/domain/Player.kt b/src/main/kotlin/racingcar/domain/Player.kt similarity index 89% rename from src/main/kotlin/domain/Player.kt rename to src/main/kotlin/racingcar/domain/Player.kt index 6509f5312..0668b76b6 100644 --- a/src/main/kotlin/domain/Player.kt +++ b/src/main/kotlin/racingcar/domain/Player.kt @@ -1,4 +1,5 @@ -package domain +package racingcar.domain + data class Player( val name: String, var winCount: Int = 0 diff --git a/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt new file mode 100644 index 000000000..d708a0f17 --- /dev/null +++ b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt @@ -0,0 +1,42 @@ +package racingcar.service + +import camp.nextstep.edu.missionutils.Console +import racingcar.domain.Player + +class CarPlayGameImpl( + private val printGame: PrintGame +) : PlayGame { + + private var round: Int = 0 + private var players: List = listOf() + override fun initGame() { + printGame.printInit() + val inputPlayers = Console.readLine() + val names = inputPlayers.split(",") + initPlayers(names) + printGame.tryCount() + round = Console.readLine().toInt() + } + + override fun initPlayers(names: List) { + players = names.map { name -> + validCheck(name) + Player.toPlayer(name) + } + } + + override fun playGame() { + } + + override fun playRound() { + } + + override fun endGame(winnerCount: Int) { + } + + private fun validCheck(name: String) { + require(name.length < 6) { + "이름의 길이는 5자이하 여야 합니다." + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/service/CarPrintGame.kt b/src/main/kotlin/racingcar/service/CarPrintGame.kt similarity index 93% rename from src/main/kotlin/service/CarPrintGame.kt rename to src/main/kotlin/racingcar/service/CarPrintGame.kt index cef756506..8cc64cc5c 100644 --- a/src/main/kotlin/service/CarPrintGame.kt +++ b/src/main/kotlin/racingcar/service/CarPrintGame.kt @@ -1,6 +1,4 @@ -package racingcar.servie - -import service.PrintGame +package racingcar.service class CarPrintGame : PrintGame { diff --git a/src/main/kotlin/service/PlayGame.kt b/src/main/kotlin/racingcar/service/PlayGame.kt similarity index 93% rename from src/main/kotlin/service/PlayGame.kt rename to src/main/kotlin/racingcar/service/PlayGame.kt index 7cdcbbb16..3cffe5c5b 100644 --- a/src/main/kotlin/service/PlayGame.kt +++ b/src/main/kotlin/racingcar/service/PlayGame.kt @@ -1,4 +1,4 @@ -package service +package racingcar.service interface PlayGame { // 게임 셋팅 diff --git a/src/main/kotlin/service/PrintGame.kt b/src/main/kotlin/racingcar/service/PrintGame.kt similarity index 93% rename from src/main/kotlin/service/PrintGame.kt rename to src/main/kotlin/racingcar/service/PrintGame.kt index 67ab75ef4..4350ba16b 100644 --- a/src/main/kotlin/service/PrintGame.kt +++ b/src/main/kotlin/racingcar/service/PrintGame.kt @@ -1,4 +1,4 @@ -package service +package racingcar.service interface PrintGame { //초기화 시 프린트 하는 메서드 From cef2f53703bf2769c5f6af4a44d9ef39a02e158c Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:32:26 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat=20(CarPlayGameImpl):=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EC=A7=84=ED=96=89=EC=9D=84=20=ED=95=A0=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20=EB=B0=8F=20readMe=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 게임 진행을 할 수 있는 기능 구현 및 readMe Update - 실제 게임이 진행되는 playGame 구현 - round 수만큼 게임 진행 - 매 round 마다 진행되는 게임 구현 - readMe Update 라운드 진행 시 랜덤으로 숫자를 뽑아 플레이어가 전진이 가능한지 멈춰야 하는지 판단하여 실제 전진시키거나 멈추도록 기능을 구현하였습니다. --- README.md | 2 +- .../racingcar/service/CarPlayGameImpl.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 439cca858..ad4e31e11 100644 --- a/README.md +++ b/README.md @@ -167,5 +167,5 @@ Randoms.pickNumberInRange(0, 9) - 기본적인 게임을 제공할 틀 만들기 v - 사용자로부터 입력을 받을 수 있는 기능 만들기 v - 받은 값을 저장할 수 있도록 기능 만들기 v -- 실제 게임을 진행하는 기능 만들기 +- 실제 게임을 진행하는 기능 만들기 v - 게임이 다 끝난 후 출력 만들기 \ No newline at end of file diff --git a/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt index d708a0f17..bae3853fe 100644 --- a/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt +++ b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt @@ -1,7 +1,9 @@ package racingcar.service import camp.nextstep.edu.missionutils.Console +import camp.nextstep.edu.missionutils.Randoms import racingcar.domain.Player +import kotlin.math.max class CarPlayGameImpl( private val printGame: PrintGame @@ -26,17 +28,39 @@ class CarPlayGameImpl( } override fun playGame() { + initGame() + + for (loop in 0.. + // 1 : go 0 : stop + if (canIGo()) player.addWinCount() + printGame.printGame(player.name, player.winCount) + } } override fun endGame(winnerCount: Int) { } + // 5자 이하의 이름인지 확인하는 메서드 private fun validCheck(name: String) { require(name.length < 6) { "이름의 길이는 5자이하 여야 합니다." } } + + // 랜덤으로 값을 뽑아 전진이 가능한지 확인하는 메서드 + // 4 이상 부터 전진한다. + private fun canIGo(): Boolean { + return Randoms.pickNumberInRange(0, 9) > RUN_OR_STOP_STANDARD + } + + companion object { + const val RUN_OR_STOP_STANDARD = 3 + } } \ No newline at end of file From 1b4be1e620d4a66cf12a636849378a3bda57e7f8 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 20:37:33 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat=20(CarPlayGameImpl):=20=EC=8A=B9?= =?UTF-8?q?=EB=A6=AC=EC=8B=9C=20=ED=98=B8=EC=B6=9C=ED=95=A0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20readMe=20Update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 승리시 호출할 기능 구현 및 readMe Update - 승리자의 전진 횟수를 알 수 있는 기능 구현 - 마지막에 누가 승리자인지 확인 구현 - 승리자 출력 적용 - readMe Update 게임이 끝나고 승리자가 누구인지 판단하여 프린트 해주는 부분 구현 했습니다. --- README.md | 2 +- src/main/kotlin/racingcar/Application.kt | 7 ++++++- .../racingcar/service/CarPlayGameImpl.kt | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ad4e31e11..e2bf20e10 100644 --- a/README.md +++ b/README.md @@ -168,4 +168,4 @@ Randoms.pickNumberInRange(0, 9) - 사용자로부터 입력을 받을 수 있는 기능 만들기 v - 받은 값을 저장할 수 있도록 기능 만들기 v - 실제 게임을 진행하는 기능 만들기 v -- 게임이 다 끝난 후 출력 만들기 \ No newline at end of file +- 게임이 다 끝난 후 출력 만들기 v \ No newline at end of file diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0d8f3a79d..ff28fe5ec 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -1,5 +1,10 @@ package racingcar +import racingcar.service.CarPlayGameImpl +import racingcar.service.CarPrintGame + fun main() { - // TODO: 프로그램 구현 + val playGame = CarPlayGameImpl(CarPrintGame()) + + playGame.playGame() } diff --git a/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt index bae3853fe..5b8076033 100644 --- a/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt +++ b/src/main/kotlin/racingcar/service/CarPlayGameImpl.kt @@ -34,6 +34,10 @@ class CarPlayGameImpl( playRound() println() } + + val winnerCount = getCurrentWinnerCount() + + endGame(winnerCount) } override fun playRound() { @@ -45,6 +49,12 @@ class CarPlayGameImpl( } override fun endGame(winnerCount: Int) { + val winnerList = mutableListOf() + players.forEach { player -> + if (player.winCount == winnerCount) winnerList.add(player.name) + } + + printGame.printWinner(winnerList) } // 5자 이하의 이름인지 확인하는 메서드 @@ -60,6 +70,15 @@ class CarPlayGameImpl( return Randoms.pickNumberInRange(0, 9) > RUN_OR_STOP_STANDARD } + // 현재 가장 많이 전진한 사람의 count를 가져오는 메서드 + private fun getCurrentWinnerCount(): Int { + var maxGoCount = 0 + + players.forEach { player -> maxGoCount = max(maxGoCount, player.winCount) } + + return maxGoCount + } + companion object { const val RUN_OR_STOP_STANDARD = 3 } From f84aa0c45a7ff42a55a27e263cd8bfbe4c97c331 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 21:34:10 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat=20(ApplicationTest):=20=EC=97=AC?= =?UTF-8?q?=EB=9F=AC=20=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 여러 경우에 대한 테스트 코드 추가 - 단독 승리인 경우 - 공동 우승인 경우 - 3명 중 1,3번째가 승리한 경우 - 혼자 경기한 경우 - 모두 전진 혹은 스탑한 경우 테스트 코드를 추가해서 기능이 문제없음을 확인했습니다. --- src/test/kotlin/racingcar/ApplicationTest.kt | 76 ++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 2cb36835c..d53336bea 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -25,6 +25,82 @@ class ApplicationTest : NsTest() { assertThrows { runException("pobi,javaji", "1") } } } + @Test + fun `단독 우승`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni", "2") + assertThat(output()).contains("pobi : ", "woni : --", "최종 우승자 : woni") + }, + STOP, MOVING_FORWARD, STOP, MOVING_FORWARD + ) + } + + @Test + fun `혼자 경기한 경우`() { + assertRandomNumberInRangeTest( + { + run("pobi", "2") + assertThat(output()).contains("pobi : ", "최종 우승자 : pobi") + }, + STOP, STOP + ) + } + + @Test + fun `1, 3번째가 우승한 경우`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni,rilla", "3") + assertThat(output()).contains("pobi : --", "woni : ", "rilla : --", "최종 우승자 : pobi, rilla") + }, + MOVING_FORWARD, STOP, MOVING_FORWARD, STOP, STOP, MOVING_FORWARD, MOVING_FORWARD, STOP, STOP + ) + } + + @Test + fun `공동 우승`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni", "1") + assertThat(output()).contains("pobi : -", "woni : -", "최종 우승자 : pobi, woni") + }, + MOVING_FORWARD, MOVING_FORWARD + ) + } + + @Test + fun `모두 전진 실패`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni", "3") + assertThat(output()).contains("pobi : ", "woni : ", "최종 우승자 : pobi, woni") + }, + STOP, STOP, STOP, STOP, STOP, STOP + ) + } + + @Test + fun `모두 전진 성공`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni", "2") + assertThat(output()).contains("pobi : --", "woni : --", "최종 우승자 : pobi, woni") + }, + MOVING_FORWARD, MOVING_FORWARD, MOVING_FORWARD, MOVING_FORWARD + ) + } + + @Test + fun `전진 스탑 스탑 전진`() { + assertRandomNumberInRangeTest( + { + run("pobi,woni", "2") + assertThat(output()).contains("pobi : -", "woni : -", "최종 우승자 : pobi, woni") + }, + MOVING_FORWARD, STOP, STOP, MOVING_FORWARD + ) + } public override fun runMain() { main() From 9c5186fc771a5f361186cadc9fcfacd4c6cf58b4 Mon Sep 17 00:00:00 2001 From: acecic82 <102938al@naver.com> Date: Wed, 1 Nov 2023 22:05:49 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat=20(ApplicationTest):=20=EC=9D=B8?= =?UTF-8?q?=EB=8D=B4=ED=8A=B8=EA=B0=80=20=EC=9E=98=EB=AA=BB=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EA=B0=80=20=ED=95=B4=EB=8B=B9=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=9E=AC=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 인덴트가 잘못들어가 해당 부분 재정렬 - 자동인덴트 적용 중 잘못 들어간 인덴트 발견하여 다시 수정 인덴트가 잘못들어간 부분 재 수정 하였습니다. --- src/main/kotlin/racingcar/domain/Player.kt | 1 + src/main/kotlin/racingcar/service/PlayGame.kt | 4 ++++ src/main/kotlin/racingcar/service/PrintGame.kt | 3 +++ src/test/kotlin/racingcar/ApplicationTest.kt | 11 ++++++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/racingcar/domain/Player.kt b/src/main/kotlin/racingcar/domain/Player.kt index 0668b76b6..58f35b859 100644 --- a/src/main/kotlin/racingcar/domain/Player.kt +++ b/src/main/kotlin/racingcar/domain/Player.kt @@ -7,6 +7,7 @@ data class Player( fun addWinCount() { winCount++ } + companion object { fun toPlayer(name: String): Player = Player(name, 0) } diff --git a/src/main/kotlin/racingcar/service/PlayGame.kt b/src/main/kotlin/racingcar/service/PlayGame.kt index 3cffe5c5b..532f9dc0f 100644 --- a/src/main/kotlin/racingcar/service/PlayGame.kt +++ b/src/main/kotlin/racingcar/service/PlayGame.kt @@ -3,12 +3,16 @@ package racingcar.service interface PlayGame { // 게임 셋팅 fun initGame() + // 플레이어 값 초기화 fun initPlayers(names: List) + // 게임의 전체 진행을 위한 메서드 fun playGame() + // 게임의 각 라운드를 위한 메서드 fun playRound() + // 게임 종료시 호출될 메서드 fun endGame(winnerCount: Int) } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/service/PrintGame.kt b/src/main/kotlin/racingcar/service/PrintGame.kt index 4350ba16b..d0f229608 100644 --- a/src/main/kotlin/racingcar/service/PrintGame.kt +++ b/src/main/kotlin/racingcar/service/PrintGame.kt @@ -3,10 +3,13 @@ package racingcar.service interface PrintGame { //초기화 시 프린트 하는 메서드 fun printInit() + //시도할 횟수에 대한 프린트 하는 메서드 fun tryCount() + // 게임 진행시 결과를 프린트 하는 메서드 fun printGame(playerName: String, goCount: Int) + // 게임 승리자를 프린트 하는 메서드 fun printWinner(names: List) } \ No newline at end of file diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index d53336bea..4f68ee16b 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -11,11 +11,11 @@ class ApplicationTest : NsTest() { @Test fun `전진 정지`() { assertRandomNumberInRangeTest( - { - run("pobi,woni", "1") - assertThat(output()).contains("pobi : -", "woni : ", "최종 우승자 : pobi") - }, - MOVING_FORWARD, STOP + { + run("pobi,woni", "1") + assertThat(output()).contains("pobi : -", "woni : ", "최종 우승자 : pobi") + }, + MOVING_FORWARD, STOP ) } @@ -25,6 +25,7 @@ class ApplicationTest : NsTest() { assertThrows { runException("pobi,javaji", "1") } } } + @Test fun `단독 우승`() { assertRandomNumberInRangeTest(