From 06413b068d09667953755acba48a9377b333aa8b Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 05:33:32 +0900 Subject: [PATCH 01/50] docs(docs/README.md): write feature list --- docs/README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..e76cd6cfe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,40 @@ +# 기능목록 + +1. 구입 금액 입력 구문 출력 +2. 구입 금액 입력 + - 예외 `IllegalArgumentException` + - 구입 금액이 숫자가 아닐 경우(문구 : [ERROR] 구입 금액은 숫자여야 합니다.) + - 구입 금액이 1000원 단위가 아닐 경우(문구 : [ERROR] 구입 금액은 1000원 단위여야 합니다.) +3. 구입 개수 계산 +4. 구입 개수 출력 +5. 구입 개수에 맞게 로또 발행 +6. 발행된 로또 출력 +7. 당첨 번호 입력 구문 출력 +8. 당첨 번호 입력 + - 당첨 번호를 쉼표를 구분자로 나누어 문자열 배열로 저장 + - 나눠진 각 문자열 예외 `IllegalArgumentException` + - 숫자가 아닐 경우(문구 : [ERROR] 당첨 번호는 숫자여야 합니다.) + - 1 ~ 45 가 아닐 경우(문구 : [ERROR] 당첨 번호는 1 ~ 45 사이여야 합니다.) + - 당첨 번호가 6개가 아닐 경우(문구 : [ERROR] 당첨 번호는 6개여야 합니다.) + - 당첨 번호가 중복될 경우(문구 : [ERROR] 당첨 번호는 중복되지 않아야 합니다.) + - 예외사항이 아니면 정수 배열로 변경 후 Lotto 클래스의 생성자에 멤버변수로 전달 +9. 보너스 번호 입력 구문 출력 +10. 보너스 번호 입력 + - 예외 `IllegalArgumentException` + - 숫자가 아닐 경우(문구 : [ERROR] 보너스 번호는 숫자여야 합니다.) + - 1 ~ 45 가 아닐 경우(문구 : [ERROR] 보너스 번호는 1 ~ 45 사이여야 합니다.) + - 보너스 번호가 1개가 아닐 경우(문구 : [ERROR] 보너스 번호는 1개여야 합니다.) + - 당첨 번호들과 중복될 경우(문구 : [ERROR] 보너스 번호는 당첨 번호와 중복되지 않아야 합니다.) +11. 발행된 로또들을 순회하며 당첨 번호와 몇 개가 일치하는지 확인 + - 3,4,6개가 일치한다면, 일치 개수에 따라 5칸짜리 정수 배열에 할당 + - 0번째 인덱스 : 3개 일치 개수 + - 1번째 인덱스 : 4개 일치 개수 + - 2번째 인덱스 : 0 + - 3번째 인덱스 : 0 + - 4번째 인덱스 : 6개 일치 개수 + - 5개가 일치한다면, 보너스 번호와 일치하는지 확인 + - 일치한다면 3번째 인덱스에 1 증가 + - 일치하지 않는다면 2번째 인덱스에 1 증가 +12. 수익률 계산 + - 수익률 = 당첨 금액 / 구입 금액 * 100 +13. 당첨 통계 및 수익률 출력 \ No newline at end of file From de4c0cb1d83e829b6b9e6c05f0e6ccb2150d94f5 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 17:33:06 +0900 Subject: [PATCH 02/50] =?UTF-8?q?feat(enumeration/PrintBuy.kt):=20enum=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B0=8F=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 열거형 PRICE 생성 --- src/main/kotlin/lotto/enumeration/PrintBuy.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/enumeration/PrintBuy.kt diff --git a/src/main/kotlin/lotto/enumeration/PrintBuy.kt b/src/main/kotlin/lotto/enumeration/PrintBuy.kt new file mode 100644 index 000000000..3c460e933 --- /dev/null +++ b/src/main/kotlin/lotto/enumeration/PrintBuy.kt @@ -0,0 +1,5 @@ +package lotto.enumeration + +enum class PrintBuy(val value: String) { + PRICE("구입금액을 입력해 주세요.") +} From d30d51ddf4a8172a07a4fd17cb180d08993c02a2 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 17:34:31 +0900 Subject: [PATCH 03/50] =?UTF-8?q?feat(LottoUI):=20UI=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B0=8F=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 printBuyPrice 생성 --- src/main/kotlin/lotto/LottoUI.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/kotlin/lotto/LottoUI.kt diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt new file mode 100644 index 000000000..162a205ef --- /dev/null +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -0,0 +1,10 @@ +package lotto + +import lotto.enumeration.PrintBuy + +class LottoUI { + fun printBuyPrice() { + println(PrintBuy.PRICE.value) + } + +} From 82234e6a29a70bf1809e503de96618cf6c5624c9 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 17:35:24 +0900 Subject: [PATCH 04/50] =?UTF-8?q?feat(main):=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EA=B5=AC=EB=AC=B8=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/main/kotlin/lotto/Application.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index d7168761c..d8eb92d01 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -1,5 +1,5 @@ package lotto fun main() { - TODO("프로그램 구현") + LottoUI().printBuyPrice() } From d22c16331c996a8770944ca71c9a17115d9bf0d9 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:14:42 +0900 Subject: [PATCH 05/50] =?UTF-8?q?feat(LottoUI):=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 정상적인 구입 금액을 String으로 return할 메서드 inputBuyPrice 구현 --- src/main/kotlin/lotto/LottoUI.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 162a205ef..94f3baad2 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -1,5 +1,6 @@ package lotto +import camp.nextstep.edu.missionutils.Console import lotto.enumeration.PrintBuy class LottoUI { @@ -7,4 +8,16 @@ class LottoUI { println(PrintBuy.PRICE.value) } + fun inputBuyPrice(): String { + val buyPrice = Console.readLine() + try { + checkInvalidBuyPrice(buyPrice) + } catch (e: IllegalArgumentException) { + println(e.message) + printBuyPrice() + return inputBuyPrice() + } + return buyPrice + } + } From 27e55f8dd576b30fe7f2eb4e971db9aade632ad1 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:16:40 +0900 Subject: [PATCH 06/50] =?UTF-8?q?feat(LottoUI):=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 예외 상활 시 IllegalArgumentException 발생 시킬 메서드 구현 --- src/main/kotlin/lotto/LottoUI.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 94f3baad2..7de55d66a 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -20,4 +20,11 @@ class LottoUI { return buyPrice } + private fun checkInvalidBuyPrice(buyPrice: String) { + when { + buyPrice.toIntOrNull() == null -> throw IllegalArgumentException("[ERROR] 구입 금액은 정수여야 합니다.") + buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException("[ERROR] 구입 금액은 1000원 단위여야 합니다.") + } + } + } From d6b8f3cd7d76b540833f13b5ba4e7a4c615ae28a Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:18:51 +0900 Subject: [PATCH 07/50] =?UTF-8?q?feat(main):=20=EC=A0=95=EC=83=81=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=20=EA=B8=88=EC=95=A1=EC=9D=84=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20buyPrice=EB=A1=9C=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/Application.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index d8eb92d01..09d00c845 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -2,4 +2,5 @@ package lotto fun main() { LottoUI().printBuyPrice() + val buyPrice = LottoUI().inputBuyPrice() } From 97f0d3d9155e69668f9e3ab33612e01883651f1a Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:26:39 +0900 Subject: [PATCH 08/50] =?UTF-8?q?docs(docs/README.md):=20=EA=B5=AC?= =?UTF-8?q?=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=98=88=EC=99=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20"=EC=88=AB=EC=9E=90"?= =?UTF-8?q?=EC=97=90=EC=84=9C=20"=EC=A0=95=EC=88=98"=EB=A1=9C=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 --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index e76cd6cfe..2c541dadb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,7 @@ 1. 구입 금액 입력 구문 출력 2. 구입 금액 입력 - 예외 `IllegalArgumentException` - - 구입 금액이 숫자가 아닐 경우(문구 : [ERROR] 구입 금액은 숫자여야 합니다.) + - 구입 금액이 정수가 아닐 경우(문구 : [ERROR] 구입 금액은 정수여야 합니다.) - 구입 금액이 1000원 단위가 아닐 경우(문구 : [ERROR] 구입 금액은 1000원 단위여야 합니다.) 3. 구입 개수 계산 4. 구입 개수 출력 From 891c0d8f59d7c926d17cd08c3ed8a599ce22ab60 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:27:43 +0900 Subject: [PATCH 09/50] =?UTF-8?q?feat(enumeration/PrintBuy.kt):=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=AC=B8=EA=B5=AC=EB=93=A4=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 --- src/main/kotlin/lotto/enumeration/PrintBuy.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/enumeration/PrintBuy.kt b/src/main/kotlin/lotto/enumeration/PrintBuy.kt index 3c460e933..7d9b8975b 100644 --- a/src/main/kotlin/lotto/enumeration/PrintBuy.kt +++ b/src/main/kotlin/lotto/enumeration/PrintBuy.kt @@ -1,5 +1,7 @@ package lotto.enumeration enum class PrintBuy(val value: String) { - PRICE("구입금액을 입력해 주세요.") + PRICE("구입금액을 입력해 주세요."), + ERROR_NOT_INTEGER("[ERROR] 구입 금액은 정수여야 합니다."), + ERROR_NOT_THOUSAND("[ERROR] 구입 금액은 1000원 단위여야 합니다.") } From 28c9424f3b347843cc6b3cd6b6d86fc55063f965 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:28:13 +0900 Subject: [PATCH 10/50] =?UTF-8?q?feat(LottoUI):=20=EA=B5=AC=EC=9E=85?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=97=B4=EA=B1=B0=ED=98=95=EB=93=A4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/LottoUI.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 7de55d66a..795154aa3 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -22,8 +22,8 @@ class LottoUI { private fun checkInvalidBuyPrice(buyPrice: String) { when { - buyPrice.toIntOrNull() == null -> throw IllegalArgumentException("[ERROR] 구입 금액은 정수여야 합니다.") - buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException("[ERROR] 구입 금액은 1000원 단위여야 합니다.") + buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(PrintBuy.ERROR_NOT_INTEGER.value) + buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(PrintBuy.ERROR_NOT_THOUSAND.value) } } From fc60c79b3e500f578051ce4d5c0b67ee63afcf2e Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:32:43 +0900 Subject: [PATCH 11/50] =?UTF-8?q?refactor(enumeration/Buy.kt):=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B0=8F=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PrintBuy -> Buy PRICE -> PRICE_INPUT --- src/main/kotlin/lotto/enumeration/{PrintBuy.kt => Buy.kt} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/kotlin/lotto/enumeration/{PrintBuy.kt => Buy.kt} (66%) diff --git a/src/main/kotlin/lotto/enumeration/PrintBuy.kt b/src/main/kotlin/lotto/enumeration/Buy.kt similarity index 66% rename from src/main/kotlin/lotto/enumeration/PrintBuy.kt rename to src/main/kotlin/lotto/enumeration/Buy.kt index 7d9b8975b..ed610773a 100644 --- a/src/main/kotlin/lotto/enumeration/PrintBuy.kt +++ b/src/main/kotlin/lotto/enumeration/Buy.kt @@ -1,7 +1,7 @@ package lotto.enumeration -enum class PrintBuy(val value: String) { - PRICE("구입금액을 입력해 주세요."), +enum class Buy(val value: String) { + PRICE_INPUT("구입금액을 입력해 주세요."), ERROR_NOT_INTEGER("[ERROR] 구입 금액은 정수여야 합니다."), ERROR_NOT_THOUSAND("[ERROR] 구입 금액은 1000원 단위여야 합니다.") } From 4244270455cf5c4c4873738d3429888ba84d4f28 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:33:15 +0900 Subject: [PATCH 12/50] =?UTF-8?q?refactor(LottoUI):=20Buy=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B0=8F=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/LottoUI.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 795154aa3..1965250f5 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -1,11 +1,11 @@ package lotto import camp.nextstep.edu.missionutils.Console -import lotto.enumeration.PrintBuy +import lotto.enumeration.Buy class LottoUI { fun printBuyPrice() { - println(PrintBuy.PRICE.value) + println(Buy.PRICE_INPUT.value) } fun inputBuyPrice(): String { @@ -22,8 +22,8 @@ class LottoUI { private fun checkInvalidBuyPrice(buyPrice: String) { when { - buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(PrintBuy.ERROR_NOT_INTEGER.value) - buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(PrintBuy.ERROR_NOT_THOUSAND.value) + buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(Buy.ERROR_NOT_INTEGER.value) + buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) } } From d450a8bc3a0b0f061042cabc79b2c57b2899a4a3 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:48:09 +0900 Subject: [PATCH 13/50] =?UTF-8?q?refactor(LottoUI):=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20checkInvalidBuyPrice=EC=9D=98=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=EC=A0=9C=EC=96=B4=EC=9E=90=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/lotto/LottoUI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 1965250f5..f89e6042d 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -20,7 +20,7 @@ class LottoUI { return buyPrice } - private fun checkInvalidBuyPrice(buyPrice: String) { + fun checkInvalidBuyPrice(buyPrice: String) { when { buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(Buy.ERROR_NOT_INTEGER.value) buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) From e711112c232ed141abfc5cf92f5e0f33e0e0c026 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:50:39 +0900 Subject: [PATCH 14/50] =?UTF-8?q?test(LottoTest.kt):=20checkInvalidBuyPric?= =?UTF-8?q?e=20=EB=8B=A8=EC=9C=84=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/lotto/LottoTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/kotlin/lotto/LottoTest.kt b/src/test/kotlin/lotto/LottoTest.kt index 11d85ac2c..9e23b4758 100644 --- a/src/test/kotlin/lotto/LottoTest.kt +++ b/src/test/kotlin/lotto/LottoTest.kt @@ -21,4 +21,20 @@ class LottoTest { } // 아래에 추가 테스트 작성 가능 + @Test + fun `구입 금액 입력 에러 발생 테스트`() { + assertThrows { + LottoUI().checkInvalidBuyPrice("abc") + } + assertThrows { + LottoUI().checkInvalidBuyPrice("1001") + } + assertThrows { + LottoUI().checkInvalidBuyPrice("0") + } + assertThrows { + LottoUI().checkInvalidBuyPrice("-1") + } + LottoUI().checkInvalidBuyPrice("1000") + } } From f6dcd66473875131ec462e47b2ce455f1268e9db Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 18:51:37 +0900 Subject: [PATCH 15/50] =?UTF-8?q?fix(LottoUI):=20checkInvalidBuyPrice=20?= =?UTF-8?q?=EC=97=90=EC=84=9C=200=EC=9B=90=20=EC=97=90=EB=9F=AC=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=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/lotto/LottoUI.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index f89e6042d..4391ed08d 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -24,6 +24,7 @@ class LottoUI { when { buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(Buy.ERROR_NOT_INTEGER.value) buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) + buyPrice.toInt() == 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) } } From a09c523849325e4fa12e3029ef21567cd5836ea6 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:19:55 +0900 Subject: [PATCH 16/50] =?UTF-8?q?feat(enumeration/Buy.kt):=20=EC=97=B4?= =?UTF-8?q?=EA=B1=B0=ED=98=95=20HOW=5FMANY=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/lotto/enumeration/Buy.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/enumeration/Buy.kt b/src/main/kotlin/lotto/enumeration/Buy.kt index ed610773a..955b73599 100644 --- a/src/main/kotlin/lotto/enumeration/Buy.kt +++ b/src/main/kotlin/lotto/enumeration/Buy.kt @@ -3,5 +3,6 @@ package lotto.enumeration enum class Buy(val value: String) { PRICE_INPUT("구입금액을 입력해 주세요."), ERROR_NOT_INTEGER("[ERROR] 구입 금액은 정수여야 합니다."), - ERROR_NOT_THOUSAND("[ERROR] 구입 금액은 1000원 단위여야 합니다.") + ERROR_NOT_THOUSAND("[ERROR] 구입 금액은 1000원 단위여야 합니다."), + HOW_MANY("개를 구매했습니다.") } From e2f08389135131c9ac1957ecb61363ea3d24a2a7 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:21:27 +0900 Subject: [PATCH 17/50] =?UTF-8?q?feat(LottoUI):=20=EB=AA=87=EA=B0=9C?= =?UTF-8?q?=EB=A5=BC=20=EA=B5=AC=EB=A7=A4=ED=96=88=EB=8A=94=EC=A7=80=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=ED=95=B4=EC=A3=BC=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=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 --- src/main/kotlin/lotto/LottoUI.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 4391ed08d..f61c55151 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -28,4 +28,10 @@ class LottoUI { } } + fun printBuyLottoCount(buyPrice: String) { + println() + print(buyPrice.toInt() / 1000) + println(Buy.HOW_MANY.value) + } + } From f02facc80ee3023dd715526de820eee94e794815 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:22:02 +0900 Subject: [PATCH 18/50] =?UTF-8?q?feat(main):=20printBuyLottoCount=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/main/kotlin/lotto/Application.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 09d00c845..d1952b9a2 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -3,4 +3,5 @@ package lotto fun main() { LottoUI().printBuyPrice() val buyPrice = LottoUI().inputBuyPrice() + LottoUI().printBuyLottoCount(buyPrice) } From 4e7dbfce4992c8004602ef4101b38d497a6d33ec Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:55:04 +0900 Subject: [PATCH 19/50] =?UTF-8?q?feat(LottoService):=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 매서드 buyLotto 생성 --- src/main/kotlin/lotto/LottoService.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/kotlin/lotto/LottoService.kt diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt new file mode 100644 index 000000000..c8f9501e6 --- /dev/null +++ b/src/main/kotlin/lotto/LottoService.kt @@ -0,0 +1,11 @@ +package lotto + +class LottoService { + fun buyLotto(buyCount: Int): List { + val buyLottos = mutableListOf() + repeat(buyCount) { + buyLottos.add(Lotto(lottoMaker())) + } + return buyLottos + } +} From 364910cc9c39da1422964186b4749ce90e50d442 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:57:34 +0900 Subject: [PATCH 20/50] =?UTF-8?q?feat(main):=20buyLotto=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 --- src/main/kotlin/lotto/Application.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index d1952b9a2..40eb63724 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -4,4 +4,6 @@ fun main() { LottoUI().printBuyPrice() val buyPrice = LottoUI().inputBuyPrice() LottoUI().printBuyLottoCount(buyPrice) + val buyCount = buyPrice.toInt() / 1000 + val buyLottos = LottoService().buyLotto(buyCount) } From cd32e1534a18693d2972f2456670c7bd3720f4da Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 19:59:08 +0900 Subject: [PATCH 21/50] =?UTF-8?q?feat(LottoService):=20=EA=B5=AC=EC=9E=85?= =?UTF-8?q?=20=EA=B0=9C=EC=88=98=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EB=B0=9C=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 lottoMaker 생성 --- src/main/kotlin/lotto/LottoService.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt index c8f9501e6..ae80138ad 100644 --- a/src/main/kotlin/lotto/LottoService.kt +++ b/src/main/kotlin/lotto/LottoService.kt @@ -1,5 +1,7 @@ package lotto +import camp.nextstep.edu.missionutils.Randoms + class LottoService { fun buyLotto(buyCount: Int): List { val buyLottos = mutableListOf() @@ -8,4 +10,10 @@ class LottoService { } return buyLottos } + + + private fun lottoMaker(): List { + return Randoms.pickUniqueNumbersInRange(1, 45, 6) + } + } From ee2223b86c30763bfa9e8bd6881d77ca72377549 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 20:06:52 +0900 Subject: [PATCH 22/50] =?UTF-8?q?refactor(Lotto*Test.kt):=20`=EA=B5=AC?= =?UTF-8?q?=EC=9E=85=20=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=9C=EC=83=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8`?= =?UTF-8?q?=20=EC=9D=B4=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LottoTest.kt에서 LottoUITest.kt로 이사 --- src/test/kotlin/lotto/LottoTest.kt | 16 ---------------- src/test/kotlin/lotto/LottoUITest.kt | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/test/kotlin/lotto/LottoUITest.kt diff --git a/src/test/kotlin/lotto/LottoTest.kt b/src/test/kotlin/lotto/LottoTest.kt index 9e23b4758..11d85ac2c 100644 --- a/src/test/kotlin/lotto/LottoTest.kt +++ b/src/test/kotlin/lotto/LottoTest.kt @@ -21,20 +21,4 @@ class LottoTest { } // 아래에 추가 테스트 작성 가능 - @Test - fun `구입 금액 입력 에러 발생 테스트`() { - assertThrows { - LottoUI().checkInvalidBuyPrice("abc") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("1001") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("0") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("-1") - } - LottoUI().checkInvalidBuyPrice("1000") - } } diff --git a/src/test/kotlin/lotto/LottoUITest.kt b/src/test/kotlin/lotto/LottoUITest.kt new file mode 100644 index 000000000..2014ba22a --- /dev/null +++ b/src/test/kotlin/lotto/LottoUITest.kt @@ -0,0 +1,23 @@ +package lotto + +import org.junit.jupiter.api.Test + +class LottoUITest { + + @Test + fun `구입 금액 입력 에러 발생 테스트`() { + org.junit.jupiter.api.assertThrows { + LottoUI().checkInvalidBuyPrice("abc") + } + org.junit.jupiter.api.assertThrows { + LottoUI().checkInvalidBuyPrice("1001") + } + org.junit.jupiter.api.assertThrows { + LottoUI().checkInvalidBuyPrice("0") + } + org.junit.jupiter.api.assertThrows { + LottoUI().checkInvalidBuyPrice("-1") + } + LottoUI().checkInvalidBuyPrice("1000") + } +} \ No newline at end of file From c15a01f7db839d438accd962b0ece96945eb973b Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:05:26 +0900 Subject: [PATCH 23/50] =?UTF-8?q?feat(Lotto.kt):=20getNumbers=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 밖에서 getter로서 사용하기 위해 메서드 생성 --- src/main/kotlin/lotto/Lotto.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/Lotto.kt b/src/main/kotlin/lotto/Lotto.kt index 5ca00b4e4..19397c406 100644 --- a/src/main/kotlin/lotto/Lotto.kt +++ b/src/main/kotlin/lotto/Lotto.kt @@ -5,5 +5,7 @@ class Lotto(private val numbers: List) { require(numbers.size == 6) } - // TODO: 추가 기능 구현 + fun getNumbers(): List { + return numbers + } } From 53afa53284980d74aa695ddf420372d573c8a203 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:07:05 +0900 Subject: [PATCH 24/50] =?UTF-8?q?feat(LottoUI):=20printLottoNumbers=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 발행한 모든 로또들을 출력하는 메서드 생성 --- src/main/kotlin/lotto/LottoUI.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index f61c55151..8035ae8a4 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -34,4 +34,11 @@ class LottoUI { println(Buy.HOW_MANY.value) } + fun printLottoNumbers(lottos: List) { + lottos.forEach { + println("${it.getNumbers()}") + } + println() + } + } From d0519e7367f9f4910fee5253a26cae8302e62cad Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:07:38 +0900 Subject: [PATCH 25/50] =?UTF-8?q?feat(main):=20printLottoNumbers=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/Application.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 40eb63724..61b680fa0 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -5,5 +5,6 @@ fun main() { val buyPrice = LottoUI().inputBuyPrice() LottoUI().printBuyLottoCount(buyPrice) val buyCount = buyPrice.toInt() / 1000 - val buyLottos = LottoService().buyLotto(buyCount) + val lottos = LottoService().buyLotto(buyCount) + LottoUI().printLottoNumbers(lottos) } From e8762cf1c985216ebff4d3f0df0d0c87b85c1d06 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:12:17 +0900 Subject: [PATCH 26/50] =?UTF-8?q?test(LottoServiceTest.kt):=20buyLotto()?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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/lotto/LottoServiceTest.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/kotlin/lotto/LottoServiceTest.kt diff --git a/src/test/kotlin/lotto/LottoServiceTest.kt b/src/test/kotlin/lotto/LottoServiceTest.kt new file mode 100644 index 000000000..193aa4ce1 --- /dev/null +++ b/src/test/kotlin/lotto/LottoServiceTest.kt @@ -0,0 +1,15 @@ +package lotto + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class LottoServiceTest { + + @Test + fun `구입 개수에 맞게 로또 발행`() { + var lotto = LottoService().buyLotto(3) + assertEquals(3, lotto.size) + lotto = LottoService().buyLotto(5) + assertEquals(5, lotto.size) + } +} \ No newline at end of file From 53744ec81eeb04d2a0a19eaa598522765541b195 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:17:24 +0900 Subject: [PATCH 27/50] =?UTF-8?q?feat(main):=20=EC=9D=B4=ED=9B=84=20?= =?UTF-8?q?=EB=BC=88=EB=8C=80(=EA=B5=AC=EC=A1=B0)=20=EB=A8=BC=EC=A0=80=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 각 메서드 구현 후 테스트 요망 --- src/main/kotlin/lotto/Application.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 61b680fa0..315d7dcd9 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -7,4 +7,9 @@ fun main() { val buyCount = buyPrice.toInt() / 1000 val lottos = LottoService().buyLotto(buyCount) LottoUI().printLottoNumbers(lottos) + LottoUI().printWinningNumbers() + val winningLotto = LottoUI().inputWinningNumbers() + LottoUI().printBonusNumber() + val bonusNumber = LottoUI().inputBonusNumber() + LottoUI().printResult(lottos, winningLotto, bonusNumber) } From 35fcc535603a9307329fa953d049a9e6e97a561a Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:23:05 +0900 Subject: [PATCH 28/50] =?UTF-8?q?feat(main):=20=EB=8B=B9=EC=B2=A8=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EA=B5=AC=EB=AC=B8=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/main/kotlin/lotto/LottoUI.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 8035ae8a4..be51b95a9 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -2,6 +2,7 @@ package lotto import camp.nextstep.edu.missionutils.Console import lotto.enumeration.Buy +import lotto.enumeration.Winning class LottoUI { fun printBuyPrice() { @@ -41,4 +42,8 @@ class LottoUI { println() } + fun printWinningNumbers() { + println(Winning.NUMBER_INPUT.value) + } + } From e7e2d008136e16374064a5be059fa77ad4677b62 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:24:20 +0900 Subject: [PATCH 29/50] =?UTF-8?q?feat(Winning):=20=EC=97=B4=EA=B1=B0?= =?UTF-8?q?=ED=98=95=20NUMBER=5FINPUT=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/lotto/enumeration/Winning.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/enumeration/Winning.kt diff --git a/src/main/kotlin/lotto/enumeration/Winning.kt b/src/main/kotlin/lotto/enumeration/Winning.kt new file mode 100644 index 000000000..0643cc19b --- /dev/null +++ b/src/main/kotlin/lotto/enumeration/Winning.kt @@ -0,0 +1,5 @@ +package lotto.enumeration + +enum class Winning(val value: String) { + NUMBER_INPUT("당첨 번호를 입력해 주세요.") +} From 12400a5a2b8cc25ed3766c98c39d8671ba59944b Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:38:18 +0900 Subject: [PATCH 30/50] =?UTF-8?q?feat(LottoUI):=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20inputWinningNumbers=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 아직 checkInvalidWinningNumbers 미구현 아직 winningNumbersToInt 미구현 --- src/main/kotlin/lotto/LottoUI.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index be51b95a9..d1361cec0 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -46,4 +46,16 @@ class LottoUI { println(Winning.NUMBER_INPUT.value) } + fun inputWinningNumbers(): Lotto { + val winningNumbers = Console.readLine().split(",") + try { + checkInvalidWinningNumbers(winningNumbers) + } catch (e: IllegalArgumentException) { + println(e.message) + printWinningNumbers() + return inputWinningNumbers() + } + return Lotto(winningNumbersToInt(winningNumbers)) + } + } From ccc197c8bcbb42e1e758171bd41b64ca6bdbd712 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:39:26 +0900 Subject: [PATCH 31/50] =?UTF-8?q?feat(LottoUI):=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20winningNumbersToInt=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/lotto/LottoUI.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index d1361cec0..cc8fab154 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -58,4 +58,8 @@ class LottoUI { return Lotto(winningNumbersToInt(winningNumbers)) } + private fun winningNumbersToInt(winningNumbers: List): List { + return winningNumbers.map { it.toInt() } + } + } From ecb0e98a3f6c42dc06306d45d06054ba93bb8243 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:49:42 +0900 Subject: [PATCH 32/50] =?UTF-8?q?feat(Winning):=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=97=B4=EA=B1=B0=ED=98=95=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 --- src/main/kotlin/lotto/enumeration/Winning.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/enumeration/Winning.kt b/src/main/kotlin/lotto/enumeration/Winning.kt index 0643cc19b..9fa25ae32 100644 --- a/src/main/kotlin/lotto/enumeration/Winning.kt +++ b/src/main/kotlin/lotto/enumeration/Winning.kt @@ -1,5 +1,9 @@ package lotto.enumeration enum class Winning(val value: String) { - NUMBER_INPUT("당첨 번호를 입력해 주세요.") + NUMBER_INPUT("당첨 번호를 입력해 주세요."), + ERROR_NOT_INTEGER("[ERROR] 당첨 번호는 정수여야 합니다."), + ERROR_NOT_RANGE("[ERROR] 당첨 번호는 1 ~ 45 사이여야 합니다."), + ERROR_NOT_SIX("[ERROR] 당첨 번호는 6개여야 합니다."), + ERROR_NOT_UNIQUE("[ERROR] 당첨 번호는 중복되지 않아야 합니다.") } From 04a147207a2f0cc427988fe854e76ccfdf70ee14 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 21:51:31 +0900 Subject: [PATCH 33/50] =?UTF-8?q?feat(LottoUI):=20checkInvalidWinningNumbe?= =?UTF-8?q?rs=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 당첨 번호 입력 시 구분자(,)로 나눠진 각 문자열의 예외 처리 완료 --- src/main/kotlin/lotto/LottoUI.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index cc8fab154..281d8d4cb 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -58,6 +58,20 @@ class LottoUI { return Lotto(winningNumbersToInt(winningNumbers)) } + private fun checkInvalidWinningNumbers(winningNumbers: List) { + when { + winningNumbers.map { it.toIntOrNull() } + .contains(null) -> throw IllegalArgumentException(Winning.ERROR_NOT_INTEGER.value) + + winningNumbers.map { it.toInt() } + .any { it !in 1..45 } -> throw IllegalArgumentException(Winning.ERROR_NOT_RANGE.value) + + winningNumbers.size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_SIX.value) + winningNumbers.map { it.toInt() } + .distinct().size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_UNIQUE.value) + } + } + private fun winningNumbersToInt(winningNumbers: List): List { return winningNumbers.map { it.toInt() } } From 5d3353c2b4a2692cdf52d41037add3e1c2f26c76 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:13:47 +0900 Subject: [PATCH 34/50] =?UTF-8?q?test(LottoUITest):=20checkInvalidWinningN?= =?UTF-8?q?umbers=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 예외 상황 시 예외 잘 처리 --- src/test/kotlin/lotto/LottoUITest.kt | 29 ++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/lotto/LottoUITest.kt b/src/test/kotlin/lotto/LottoUITest.kt index 2014ba22a..5062b5ab2 100644 --- a/src/test/kotlin/lotto/LottoUITest.kt +++ b/src/test/kotlin/lotto/LottoUITest.kt @@ -1,23 +1,44 @@ package lotto import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows class LottoUITest { @Test fun `구입 금액 입력 에러 발생 테스트`() { - org.junit.jupiter.api.assertThrows { + assertThrows { LottoUI().checkInvalidBuyPrice("abc") } - org.junit.jupiter.api.assertThrows { + assertThrows { LottoUI().checkInvalidBuyPrice("1001") } - org.junit.jupiter.api.assertThrows { + assertThrows { LottoUI().checkInvalidBuyPrice("0") } - org.junit.jupiter.api.assertThrows { + assertThrows { LottoUI().checkInvalidBuyPrice("-1") } LottoUI().checkInvalidBuyPrice("1000") } + + @Test + fun `당첨 번호 입력 에러 발생 테스트`() { + assertThrows { + LottoUI().checkInvalidWinningNumbers("a,b,c,d,5,6".split(",")) + } + assertThrows { + LottoUI().checkInvalidWinningNumbers("100,2,3,4,50,60".split(",")) + } + assertThrows { + LottoUI().checkInvalidWinningNumbers("1,2,3,4,5".split(",")) + } + assertThrows { + LottoUI().checkInvalidWinningNumbers("1,2,3,4,5,6,7".split(",")) + } + assertThrows { + LottoUI().checkInvalidWinningNumbers("1,2,6,4,5,6".split(",")) + } + LottoUI().checkInvalidWinningNumbers("1,2,3,4,5,6".split(",")) + } } \ No newline at end of file From 19759366d7413b08795a722af840e2f04c4d1205 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:15:02 +0900 Subject: [PATCH 35/50] =?UTF-8?q?test(LottoUI):=20checkInvalidWinningNumbe?= =?UTF-8?q?rs=20=EC=9D=98=20=EC=A0=91=EA=B7=BC=EC=A0=9C=ED=95=9C=EC=9E=90?= =?UTF-8?q?=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/lotto/LottoUI.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 281d8d4cb..136d78c9a 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -58,7 +58,7 @@ class LottoUI { return Lotto(winningNumbersToInt(winningNumbers)) } - private fun checkInvalidWinningNumbers(winningNumbers: List) { + fun checkInvalidWinningNumbers(winningNumbers: List) { when { winningNumbers.map { it.toIntOrNull() } .contains(null) -> throw IllegalArgumentException(Winning.ERROR_NOT_INTEGER.value) From 20e5e54a9bcccc0c715c73a60dab5aa2afbbdeb2 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:15:39 +0900 Subject: [PATCH 36/50] =?UTF-8?q?test(Lotto):=20=EC=A4=91=EB=B3=B5?= =?UTF-8?q?=EC=9D=B4=20=EB=93=A4=EC=96=B4=EC=99=94=EC=9D=84=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EB=B6=88=ED=97=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/Lotto.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/Lotto.kt b/src/main/kotlin/lotto/Lotto.kt index 19397c406..4fbe51f26 100644 --- a/src/main/kotlin/lotto/Lotto.kt +++ b/src/main/kotlin/lotto/Lotto.kt @@ -3,6 +3,7 @@ package lotto class Lotto(private val numbers: List) { init { require(numbers.size == 6) + require(numbers.distinct().size == 6) } fun getNumbers(): List { From 3e36af87c4f08a5f8dc37f8022f5a95a8029f3b3 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:35:10 +0900 Subject: [PATCH 37/50] =?UTF-8?q?refactor:=20LottoUI=EC=97=90=20=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EA=B2=83=EB=93=A4=20LottoService=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 각 Test 클래스의 테스트들도 적용되면서, UI테스트는 사라짐 --- src/main/kotlin/lotto/LottoService.kt | 23 ++++++++++++ src/main/kotlin/lotto/LottoUI.kt | 27 ++------------ src/test/kotlin/lotto/LottoServiceTest.kt | 38 ++++++++++++++++++++ src/test/kotlin/lotto/LottoUITest.kt | 44 ----------------------- 4 files changed, 64 insertions(+), 68 deletions(-) delete mode 100644 src/test/kotlin/lotto/LottoUITest.kt diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt index ae80138ad..ef33b4fd7 100644 --- a/src/main/kotlin/lotto/LottoService.kt +++ b/src/main/kotlin/lotto/LottoService.kt @@ -1,6 +1,8 @@ package lotto import camp.nextstep.edu.missionutils.Randoms +import lotto.enumeration.Buy +import lotto.enumeration.Winning class LottoService { fun buyLotto(buyCount: Int): List { @@ -16,4 +18,25 @@ class LottoService { return Randoms.pickUniqueNumbersInRange(1, 45, 6) } + fun checkInvalidBuyPrice(buyPrice: String) { + when { + buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(Buy.ERROR_NOT_INTEGER.value) + buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) + buyPrice.toInt() == 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) + } + } + + fun checkInvalidWinningNumbers(winningNumbers: List) { + when { + winningNumbers.map { it.toIntOrNull() } + .contains(null) -> throw IllegalArgumentException(Winning.ERROR_NOT_INTEGER.value) + + winningNumbers.map { it.toInt() } + .any { it !in 1..45 } -> throw IllegalArgumentException(Winning.ERROR_NOT_RANGE.value) + + winningNumbers.size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_SIX.value) + winningNumbers.map { it.toInt() } + .distinct().size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_UNIQUE.value) + } + } } diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 136d78c9a..9d70ca19d 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -1,6 +1,7 @@ package lotto import camp.nextstep.edu.missionutils.Console +import lotto.enumeration.Bonus import lotto.enumeration.Buy import lotto.enumeration.Winning @@ -12,7 +13,7 @@ class LottoUI { fun inputBuyPrice(): String { val buyPrice = Console.readLine() try { - checkInvalidBuyPrice(buyPrice) + LottoService().checkInvalidBuyPrice(buyPrice) } catch (e: IllegalArgumentException) { println(e.message) printBuyPrice() @@ -21,14 +22,6 @@ class LottoUI { return buyPrice } - fun checkInvalidBuyPrice(buyPrice: String) { - when { - buyPrice.toIntOrNull() == null -> throw IllegalArgumentException(Buy.ERROR_NOT_INTEGER.value) - buyPrice.toInt() % 1000 != 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) - buyPrice.toInt() == 0 -> throw IllegalArgumentException(Buy.ERROR_NOT_THOUSAND.value) - } - } - fun printBuyLottoCount(buyPrice: String) { println() print(buyPrice.toInt() / 1000) @@ -49,7 +42,7 @@ class LottoUI { fun inputWinningNumbers(): Lotto { val winningNumbers = Console.readLine().split(",") try { - checkInvalidWinningNumbers(winningNumbers) + LottoService().checkInvalidWinningNumbers(winningNumbers) } catch (e: IllegalArgumentException) { println(e.message) printWinningNumbers() @@ -58,20 +51,6 @@ class LottoUI { return Lotto(winningNumbersToInt(winningNumbers)) } - fun checkInvalidWinningNumbers(winningNumbers: List) { - when { - winningNumbers.map { it.toIntOrNull() } - .contains(null) -> throw IllegalArgumentException(Winning.ERROR_NOT_INTEGER.value) - - winningNumbers.map { it.toInt() } - .any { it !in 1..45 } -> throw IllegalArgumentException(Winning.ERROR_NOT_RANGE.value) - - winningNumbers.size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_SIX.value) - winningNumbers.map { it.toInt() } - .distinct().size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_UNIQUE.value) - } - } - private fun winningNumbersToInt(winningNumbers: List): List { return winningNumbers.map { it.toInt() } } diff --git a/src/test/kotlin/lotto/LottoServiceTest.kt b/src/test/kotlin/lotto/LottoServiceTest.kt index 193aa4ce1..9ec2dcaa1 100644 --- a/src/test/kotlin/lotto/LottoServiceTest.kt +++ b/src/test/kotlin/lotto/LottoServiceTest.kt @@ -2,6 +2,7 @@ package lotto import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows class LottoServiceTest { @@ -12,4 +13,41 @@ class LottoServiceTest { lotto = LottoService().buyLotto(5) assertEquals(5, lotto.size) } + + @Test + fun `구입 금액 입력 에러 발생 테스트`() { + assertThrows { + LottoService().checkInvalidBuyPrice("abc") + } + assertThrows { + LottoService().checkInvalidBuyPrice("1001") + } + assertThrows { + LottoService().checkInvalidBuyPrice("0") + } + assertThrows { + LottoService().checkInvalidBuyPrice("-1") + } + LottoService().checkInvalidBuyPrice("1000") + } + + @Test + fun `당첨 번호 입력 에러 발생 테스트`() { + assertThrows { + LottoService().checkInvalidWinningNumbers("a,b,c,d,5,6".split(",")) + } + assertThrows { + LottoService().checkInvalidWinningNumbers("100,2,3,4,50,60".split(",")) + } + assertThrows { + LottoService().checkInvalidWinningNumbers("1,2,3,4,5".split(",")) + } + assertThrows { + LottoService().checkInvalidWinningNumbers("1,2,3,4,5,6,7".split(",")) + } + assertThrows { + LottoService().checkInvalidWinningNumbers("1,2,6,4,5,6".split(",")) + } + LottoService().checkInvalidWinningNumbers("1,2,3,4,5,6".split(",")) + } } \ No newline at end of file diff --git a/src/test/kotlin/lotto/LottoUITest.kt b/src/test/kotlin/lotto/LottoUITest.kt deleted file mode 100644 index 5062b5ab2..000000000 --- a/src/test/kotlin/lotto/LottoUITest.kt +++ /dev/null @@ -1,44 +0,0 @@ -package lotto - -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertThrows - -class LottoUITest { - - @Test - fun `구입 금액 입력 에러 발생 테스트`() { - assertThrows { - LottoUI().checkInvalidBuyPrice("abc") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("1001") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("0") - } - assertThrows { - LottoUI().checkInvalidBuyPrice("-1") - } - LottoUI().checkInvalidBuyPrice("1000") - } - - @Test - fun `당첨 번호 입력 에러 발생 테스트`() { - assertThrows { - LottoUI().checkInvalidWinningNumbers("a,b,c,d,5,6".split(",")) - } - assertThrows { - LottoUI().checkInvalidWinningNumbers("100,2,3,4,50,60".split(",")) - } - assertThrows { - LottoUI().checkInvalidWinningNumbers("1,2,3,4,5".split(",")) - } - assertThrows { - LottoUI().checkInvalidWinningNumbers("1,2,3,4,5,6,7".split(",")) - } - assertThrows { - LottoUI().checkInvalidWinningNumbers("1,2,6,4,5,6".split(",")) - } - LottoUI().checkInvalidWinningNumbers("1,2,3,4,5,6".split(",")) - } -} \ No newline at end of file From 278255a16f0affe430f48a345d4d685a29fdea79 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:37:25 +0900 Subject: [PATCH 38/50] =?UTF-8?q?feat(Bonus):=20=EB=B3=B4=EB=84=88?= =?UTF-8?q?=EC=8A=A4=EB=B2=88=ED=98=B8=EC=97=90=20=EA=B4=80=ED=95=9C=20enu?= =?UTF-8?q?m=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=B0=8F=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=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/lotto/enumeration/Bonus.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/kotlin/lotto/enumeration/Bonus.kt diff --git a/src/main/kotlin/lotto/enumeration/Bonus.kt b/src/main/kotlin/lotto/enumeration/Bonus.kt new file mode 100644 index 000000000..5369b04ae --- /dev/null +++ b/src/main/kotlin/lotto/enumeration/Bonus.kt @@ -0,0 +1,9 @@ +package lotto.enumeration + +enum class Bonus(val value: String) { + NUMBER_INPUT("보너스 번호를 입력해 주세요."), + ERROR_NOT_INTEGER("[ERROR] 당첨 번호는 정수여야 합니다."), + ERROR_NOT_RANGE("[ERROR] 당첨 번호는 1 ~ 45 사이여야 합니다."), + ERROR_NOT_SIX("[ERROR] 당첨 번호는 6개여야 합니다."), + ERROR_NOT_UNIQUE("[ERROR] 당첨 번호는 중복되지 않아야 합니다.") +} \ No newline at end of file From c81e313713f27ebd0251f42e9d48df1eaceeb954 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:38:17 +0900 Subject: [PATCH 39/50] =?UTF-8?q?feat(LottoUI):=20printBonusNumber=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 보너스 번호 입력 구문 출력 --- src/main/kotlin/lotto/LottoUI.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 9d70ca19d..48eb92ba9 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -55,4 +55,8 @@ class LottoUI { return winningNumbers.map { it.toInt() } } + fun printBonusNumber() { + println(Bonus.NUMBER_INPUT.value) + } + } From 9a80d000b5d1f5ae960e05c6de38a16b75d2d289 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:51:45 +0900 Subject: [PATCH 40/50] =?UTF-8?q?docs(docs/README.md):=20=EB=B3=B4?= =?UTF-8?q?=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=98=88=EC=99=B8=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 숫자가 아닌 경우가 아닌 정수가 아닌 경우를 걸러야 함 1개가 아닌 경우는 들어오지 않음 --- docs/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2c541dadb..ad30c01bb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,9 +21,8 @@ 9. 보너스 번호 입력 구문 출력 10. 보너스 번호 입력 - 예외 `IllegalArgumentException` - - 숫자가 아닐 경우(문구 : [ERROR] 보너스 번호는 숫자여야 합니다.) + - 정수가 아닐 경우(문구 : [ERROR] 보너스 번호는 정수여야 합니다.) - 1 ~ 45 가 아닐 경우(문구 : [ERROR] 보너스 번호는 1 ~ 45 사이여야 합니다.) - - 보너스 번호가 1개가 아닐 경우(문구 : [ERROR] 보너스 번호는 1개여야 합니다.) - 당첨 번호들과 중복될 경우(문구 : [ERROR] 보너스 번호는 당첨 번호와 중복되지 않아야 합니다.) 11. 발행된 로또들을 순회하며 당첨 번호와 몇 개가 일치하는지 확인 - 3,4,6개가 일치한다면, 일치 개수에 따라 5칸짜리 정수 배열에 할당 From e9a63b0d2471e3483be98dfdf723464061b77167 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:52:39 +0900 Subject: [PATCH 41/50] =?UTF-8?q?feat(Bonus):=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EB=90=9C=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/enumeration/Bonus.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/lotto/enumeration/Bonus.kt b/src/main/kotlin/lotto/enumeration/Bonus.kt index 5369b04ae..9d4e0510e 100644 --- a/src/main/kotlin/lotto/enumeration/Bonus.kt +++ b/src/main/kotlin/lotto/enumeration/Bonus.kt @@ -2,8 +2,7 @@ package lotto.enumeration enum class Bonus(val value: String) { NUMBER_INPUT("보너스 번호를 입력해 주세요."), - ERROR_NOT_INTEGER("[ERROR] 당첨 번호는 정수여야 합니다."), - ERROR_NOT_RANGE("[ERROR] 당첨 번호는 1 ~ 45 사이여야 합니다."), - ERROR_NOT_SIX("[ERROR] 당첨 번호는 6개여야 합니다."), - ERROR_NOT_UNIQUE("[ERROR] 당첨 번호는 중복되지 않아야 합니다.") + ERROR_NOT_INTEGER("[ERROR] 보너스 번호는 정수여야 합니다."), + ERROR_NOT_RANGE("[ERROR] 보너스 번호는 1 ~ 45 사이여야 합니다."), + ERROR_NOT_UNIQUE("[ERROR] 보너스 번호는 당첨 번호와 중복되지 않아야 합니다.") } \ No newline at end of file From 041a734cf9f24f211bffc8120e3d9391123a2846 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:54:08 +0900 Subject: [PATCH 42/50] =?UTF-8?q?feat(LottoUI):=20=EB=B3=B4=EB=84=88?= =?UTF-8?q?=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 inputBonusNumber 구현 완료 --- src/main/kotlin/lotto/LottoUI.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 48eb92ba9..98b760162 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -59,4 +59,16 @@ class LottoUI { println(Bonus.NUMBER_INPUT.value) } + fun inputBonusNumber(winningLotto: Lotto): Int { + val bonusNumber = Console.readLine() + try { + LottoService().checkInvalidBonusNumber(bonusNumber, winningLotto) + } catch (e: IllegalArgumentException) { + println(e.message) + printBonusNumber() + return inputBonusNumber(winningLotto) + } + return bonusNumber.toInt() + } + } From 7336ab6cde8c3bb2d466bc5b860d12fa5efc5bf4 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 22:55:06 +0900 Subject: [PATCH 43/50] =?UTF-8?q?feat(LottoService):=20=EB=B3=B4=EB=84=88?= =?UTF-8?q?=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 checkInvalidBonusNumber 구현 완료 --- src/main/kotlin/lotto/LottoService.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt index ef33b4fd7..3af9977f3 100644 --- a/src/main/kotlin/lotto/LottoService.kt +++ b/src/main/kotlin/lotto/LottoService.kt @@ -1,6 +1,7 @@ package lotto import camp.nextstep.edu.missionutils.Randoms +import lotto.enumeration.Bonus import lotto.enumeration.Buy import lotto.enumeration.Winning @@ -39,4 +40,12 @@ class LottoService { .distinct().size != 6 -> throw IllegalArgumentException(Winning.ERROR_NOT_UNIQUE.value) } } + + fun checkInvalidBonusNumber(bonusNumber: String, winningLotto: Lotto) { + when { + bonusNumber.toIntOrNull() == null -> throw IllegalArgumentException(Bonus.ERROR_NOT_INTEGER.value) + bonusNumber.toInt() !in 1..45 -> throw IllegalArgumentException(Bonus.ERROR_NOT_RANGE.value) + bonusNumber.toInt() in winningLotto.getNumbers() -> throw IllegalArgumentException(Bonus.ERROR_NOT_UNIQUE.value) + } + } } From ae5a77d6eff4125164be22c21983370cc32134f3 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:00:22 +0900 Subject: [PATCH 44/50] =?UTF-8?q?test(LottoServiceTest.kt):=20=EB=B3=B4?= =?UTF-8?q?=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=B0=9C=EC=83=9D=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/lotto/LottoServiceTest.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/kotlin/lotto/LottoServiceTest.kt b/src/test/kotlin/lotto/LottoServiceTest.kt index 9ec2dcaa1..71de7d058 100644 --- a/src/test/kotlin/lotto/LottoServiceTest.kt +++ b/src/test/kotlin/lotto/LottoServiceTest.kt @@ -50,4 +50,19 @@ class LottoServiceTest { } LottoService().checkInvalidWinningNumbers("1,2,3,4,5,6".split(",")) } + + @Test + fun `보너스 번호 입력 에러 발생 테스트`() { + val lottoNumbers = Lotto("1,2,3,4,5,6".split(",").map { it.toInt() }) + assertThrows { + LottoService().checkInvalidBonusNumber("a", lottoNumbers) + } + assertThrows { + LottoService().checkInvalidBonusNumber("100", lottoNumbers) + } + assertThrows { + LottoService().checkInvalidBonusNumber("1", lottoNumbers) + } + LottoService().checkInvalidBonusNumber("7", lottoNumbers) + } } \ No newline at end of file From 75e9a195fbcb6618d3a00b60dad3e0e1a1f1257e Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:09:20 +0900 Subject: [PATCH 45/50] =?UTF-8?q?feat(LottoUI):=20=EB=8B=B9=EC=B2=A8=20?= =?UTF-8?q?=ED=86=B5=EA=B3=84=20UI=20=EC=B6=9C=EB=A0=A5=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 printResult 형태만 구현 println위치 약간 수정 --- src/main/kotlin/lotto/LottoUI.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 98b760162..1cff19307 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -32,10 +32,10 @@ class LottoUI { lottos.forEach { println("${it.getNumbers()}") } - println() } fun printWinningNumbers() { + println() println(Winning.NUMBER_INPUT.value) } @@ -56,6 +56,7 @@ class LottoUI { } fun printBonusNumber() { + println() println(Bonus.NUMBER_INPUT.value) } @@ -71,4 +72,9 @@ class LottoUI { return bonusNumber.toInt() } + fun printResult(lottos: List, winningLotto: Lotto, bonusNumber: Int) { + println() + println("당첨통계") + } + } From 14bea981b43f1317f432bf04a167114a7d30a740 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:10:27 +0900 Subject: [PATCH 46/50] =?UTF-8?q?fix(main):=20inputBonusNumber=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=B3=80=EA=B2=BD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 보너스 번호는 당첨 번호와 겹치면 안 되기에 인자로 당첨번호를 넘겨줌 --- src/main/kotlin/lotto/Application.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 315d7dcd9..3db9bcb38 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -10,6 +10,6 @@ fun main() { LottoUI().printWinningNumbers() val winningLotto = LottoUI().inputWinningNumbers() LottoUI().printBonusNumber() - val bonusNumber = LottoUI().inputBonusNumber() + val bonusNumber = LottoUI().inputBonusNumber(winningLotto) LottoUI().printResult(lottos, winningLotto, bonusNumber) } From 05b3557b48f873c427ba187b6272a55a6504f09e Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:28:55 +0900 Subject: [PATCH 47/50] =?UTF-8?q?feat(WinningResult):=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=20=ED=86=B5=EA=B3=84=20=EC=B6=9C=EB=A0=A5=EC=9A=A9=20enum=20cl?= =?UTF-8?q?ass=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/lotto/enumeration/WinningResult.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/kotlin/lotto/enumeration/WinningResult.kt diff --git a/src/main/kotlin/lotto/enumeration/WinningResult.kt b/src/main/kotlin/lotto/enumeration/WinningResult.kt new file mode 100644 index 000000000..7eeb8642e --- /dev/null +++ b/src/main/kotlin/lotto/enumeration/WinningResult.kt @@ -0,0 +1,13 @@ +package lotto.enumeration + +enum class WinningResult(val value: String) { + STATISTIC("당첨 통계\n---"), + THREE_COUNT("3개 일치 (5,000원) - "), + FOUR_COUNT("4개 일치 (50,000원) - "), + FIVE_COUNT("5개 일치 (1,500,000원) - "), + FIVE_COUNT_WITH_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원) - "), + SIX_COUNT("6개 일치 (2,000,000,000원) - "), + UNIT("개"), + ALL_EARN_RATE("총 수익률은 "), + END_PERCENT("%입니다."); +} From a6883b8dbbe8936bc0181c31b87a8f5367b986f7 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:30:23 +0900 Subject: [PATCH 48/50] =?UTF-8?q?feat(LottoUI):=20printResult=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LottoService에서 나머지 함수 구현 요망 --- src/main/kotlin/lotto/LottoUI.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/LottoUI.kt b/src/main/kotlin/lotto/LottoUI.kt index 1cff19307..dda32eddd 100644 --- a/src/main/kotlin/lotto/LottoUI.kt +++ b/src/main/kotlin/lotto/LottoUI.kt @@ -4,6 +4,7 @@ import camp.nextstep.edu.missionutils.Console import lotto.enumeration.Bonus import lotto.enumeration.Buy import lotto.enumeration.Winning +import lotto.enumeration.WinningResult class LottoUI { fun printBuyPrice() { @@ -74,7 +75,15 @@ class LottoUI { fun printResult(lottos: List, winningLotto: Lotto, bonusNumber: Int) { println() - println("당첨통계") + println(WinningResult.STATISTIC.value) + val result: List = LottoService().LottoResult(lottos, winningLotto, bonusNumber) + println("${WinningResult.THREE_COUNT.value}${result[0]}${WinningResult.UNIT.value}") + println("${WinningResult.FOUR_COUNT.value}${result[1]}${WinningResult.UNIT.value}") + println("${WinningResult.FIVE_COUNT.value}${result[2]}${WinningResult.UNIT.value}") + println("${WinningResult.FIVE_COUNT_WITH_BONUS.value}${result[3]}${WinningResult.UNIT.value}") + println("${WinningResult.SIX_COUNT.value}${result[4]}${WinningResult.UNIT.value}") + val earnRate = LottoService().calculateEarnRate(result) + println("${WinningResult.ALL_EARN_RATE.value}${earnRate}${WinningResult.END_PERCENT.value}") } } From ba8c74c3fd59439cbde561f421ee2e3a3f4699de Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:51:37 +0900 Subject: [PATCH 49/50] =?UTF-8?q?feat(LottoService):=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=20=ED=86=B5=EA=B3=84=20=EA=B3=84=EC=82=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/Lotto.kt | 8 ++++++++ src/main/kotlin/lotto/LottoService.kt | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/main/kotlin/lotto/Lotto.kt b/src/main/kotlin/lotto/Lotto.kt index 4fbe51f26..62f28a80b 100644 --- a/src/main/kotlin/lotto/Lotto.kt +++ b/src/main/kotlin/lotto/Lotto.kt @@ -9,4 +9,12 @@ class Lotto(private val numbers: List) { fun getNumbers(): List { return numbers } + + fun matchCount(winningLotto: Lotto): Any { + return numbers.intersect(winningLotto.getNumbers().toSet()).size + } + + fun matchBonusNumber(bonusNumber: Int): Boolean { + return numbers.contains(bonusNumber) + } } diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt index 3af9977f3..2209d2f7f 100644 --- a/src/main/kotlin/lotto/LottoService.kt +++ b/src/main/kotlin/lotto/LottoService.kt @@ -48,4 +48,30 @@ class LottoService { bonusNumber.toInt() in winningLotto.getNumbers() -> throw IllegalArgumentException(Bonus.ERROR_NOT_UNIQUE.value) } } + + fun LottoResult(lottos: List, winningLotto: Lotto, bonusNumber: Int): List { + val result = mutableListOf(0, 0, 0, 0, 0, 0) + lottos.forEach { + when (it.matchCount(winningLotto)) { + 3 -> result[0]++ + 4 -> result[1]++ + 5 -> { + if (it.matchBonusNumber(bonusNumber)) { + result[3]++ + } else { + result[2]++ + } + } + + 6 -> result[4]++ + else -> result[5]++ + } + } + return result + } + + fun calculateEarnRate(result: List): Any { + val total = result.sum() + return (result[0] * 5000 + result[1] * 50000 + result[2] * 1500000 + result[3] * 30000000 + result[4] * 2000000000) / (total * 100) + } } From 4f3914b7fea4799b648d846030bbe98b2b1cb737 Mon Sep 17 00:00:00 2001 From: Jtility Date: Wed, 8 Nov 2023 23:57:37 +0900 Subject: [PATCH 50/50] =?UTF-8?q?feat(LottoService):=20=EC=B5=9C=EC=A2=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/LottoService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/lotto/LottoService.kt b/src/main/kotlin/lotto/LottoService.kt index 2209d2f7f..437ac45b7 100644 --- a/src/main/kotlin/lotto/LottoService.kt +++ b/src/main/kotlin/lotto/LottoService.kt @@ -62,7 +62,6 @@ class LottoService { result[2]++ } } - 6 -> result[4]++ else -> result[5]++ } @@ -72,6 +71,8 @@ class LottoService { fun calculateEarnRate(result: List): Any { val total = result.sum() - return (result[0] * 5000 + result[1] * 50000 + result[2] * 1500000 + result[3] * 30000000 + result[4] * 2000000000) / (total * 100) + val rate = + (result[0] * 5000 + result[1] * 50000 + result[2] * 1500000 + result[3] * 30000000 + result[4] * 2000000000).toDouble() / (total * 1000) * 100 + return "%.2f".format(rate).toDouble() } }