From 898e84915b3fee80f48e3e5d64769fa8f8a0e5b1 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 01:56:23 +0900 Subject: [PATCH 01/59] =?UTF-8?q?chore(.gitignore)=20:=20=EB=A1=9C?= =?UTF-8?q?=EC=BB=AC=20=EC=84=A4=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20local.pro?= =?UTF-8?q?perties=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5dca701a7..dff8b906c 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ out/ ### Mac OS ### .DS_Store + +# Local configuration file (sdk path, etc) +local.properties \ No newline at end of file From 7559f42a436373c04f5b4d3b805bda401ffbc73d Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 01:56:47 +0900 Subject: [PATCH 02/59] =?UTF-8?q?docs($README.md)=20:=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=A0=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fc0ae874..12721772f 100644 --- a/README.md +++ b/README.md @@ -1 +1,63 @@ -# kotlin-lotto-precourse +# 프리코스 3주차 _ 로또 + +## 📍 구현할 기능 목록 +1. 로또 금액 입력받기 + - [ ] '구입금액을 입력해 주세요.' 메시지 출력 + - [ ] 사용자 입력 받기 + - 입력받은 로또 금액 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) + - [ ] 빈 값을 입력한 경우 + - [ ] 양의 정수가 아닌 값을 입력한 경우 + - [ ] 숫자가 아닌 값을 입력한 경우 + - [ ] Int 범위를 벗어나는 값을 입력한 경우 + - [ ] 1000원으로 나누어 떨어지지 않는 경우 + +
+ +2. 로또 번호 생성 + - [ ] 로또 번호를 생성 + - [ ] `Randoms.pickUniqueNumbersInRange(1, 45, 6)` 이용 + - 제공된 `Lotto` 클래스를 사용하여 구현 + +
+ +3. 발행한 로또 수량 및 번호 출력 + - [ ] 입력한 금액만큼 발행한 로또 수량 출력 + - [ ] 수량만큼 발행된 번호 출력 + +
+ +4. 당첨 번호 입력받기 + - [ ] '당첨 번호를 입력해 주세요.' 메시지 출력 + - [ ] 사용자 입력 입력받기 + - 입력받은 당첨 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) + - [ ] 빈 값을 입력한 경우 + - [ ] 구분자로 쉼표를 사용하지 않은 경우 (문자열로 처리해서 에러 발생) + - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 + - [ ] 6개보다 적거나 6개를 넘게 입력한 경우 + +
+ +5. 보너스 번호 입력받기 + - [ ] '보너스 번호를 입력해 주세요.' 메시지 출력 + - [ ] 사용자 입력받기 + - 입력받은 보너스 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) + - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 + - [ ] 빈 값을 입력한 경우 + +
+ +6. 당첨 내역 출력하기 + - [ ] 당첨금은 3자리 마다 쉼표(,)로 구분 + - [ ] 3개부터 6까지 일치하는 내역 계산 + - [ ] 당첨 내역 출력 + +
+ +7. 수익률 출력하기 + - [ ] `당첨금액 / 구입금액` 으로 수익률 계산 + - [ ] 수익률 결과값은 소수점 둘째 자리에서 반올림 + +
+ +8. 단위 테스트 진행하기 + - [ ] 구현한 기능에 대한 단위 테스트 진행 \ No newline at end of file From dc6d616afc4581a5ebe92170407ea0a49463ab5c Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 19:14:59 +0900 Subject: [PATCH 03/59] =?UTF-8?q?docs($README.md)=20:=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=ED=95=A0=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12721772f..7b8d29229 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ - 입력받은 보너스 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 - [ ] 빈 값을 입력한 경우 + - [ ] 당첨 번호와 중복되는 경우
@@ -54,7 +55,7 @@
7. 수익률 출력하기 - - [ ] `당첨금액 / 구입금액` 으로 수익률 계산 + - [ ] `당첨금액 / 구입금액 * 100` 으로 수익률 계산 - [ ] 수익률 결과값은 소수점 둘째 자리에서 반올림
From 53b58572caa1b6166ce65d7403ce1af6ab55b370 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:05:43 +0900 Subject: [PATCH 04/59] =?UTF-8?q?refactor(Lotto.kt):=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/{ => model}/Lotto.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/kotlin/lotto/{ => model}/Lotto.kt (89%) diff --git a/src/main/kotlin/lotto/Lotto.kt b/src/main/kotlin/lotto/model/Lotto.kt similarity index 89% rename from src/main/kotlin/lotto/Lotto.kt rename to src/main/kotlin/lotto/model/Lotto.kt index b97abc385..1ddf12bb3 100644 --- a/src/main/kotlin/lotto/Lotto.kt +++ b/src/main/kotlin/lotto/model/Lotto.kt @@ -1,4 +1,4 @@ -package lotto +package lotto.model class Lotto(private val numbers: List) { init { @@ -6,4 +6,4 @@ class Lotto(private val numbers: List) { } // TODO: 추가 기능 구현 -} +} \ No newline at end of file From 32e7d13f5d2e274b1747d3746bcf56e563683c48 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:09:59 +0900 Subject: [PATCH 05/59] =?UTF-8?q?feat(ExceptionConstants.kt):=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20ExceptionConstants=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/main/kotlin/lotto/util/ExceptionConstants.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/util/ExceptionConstants.kt diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt new file mode 100644 index 000000000..ffc62808f --- /dev/null +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -0,0 +1,5 @@ +package lotto.util + +class ExceptionConstants { + +} \ No newline at end of file From c8da03c6493f6a3091182e998b867adcd1a2e418 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:10:42 +0900 Subject: [PATCH 06/59] =?UTF-8?q?feat(ExceptionConstants.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EB=A9=94=EC=8B=9C=EC=A7=80=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/util/ExceptionConstants.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt index ffc62808f..2c9179b00 100644 --- a/src/main/kotlin/lotto/util/ExceptionConstants.kt +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -1,5 +1,9 @@ package lotto.util class ExceptionConstants { - + companion object { + const val ERROR_INVALID_WINNING_NUMBERS_COUNT = "[ERROR] 로또 번호는 6개여야 합니다." + const val ERROR_INVALID_WINNING_NUMBERS_RANGE = "[ERROR] 로또 번호는 1부터 45 사이여야 합니다." + const val ERROR_DUPLICATE_WINNING_NUMBERS = "[ERROR] 로또 번호는 중복될 수 없습니다." + } } \ No newline at end of file From a5f9a7cb38afdeda44d28c789c8f61ce34c1b5c0 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:11:50 +0900 Subject: [PATCH 07/59] =?UTF-8?q?feat(Lotto.kt):=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 로또 번호 6개 입력, 1부터 45 사이의 숫자인지, 중복된 값이 없는지 검사 --- src/main/kotlin/lotto/model/Lotto.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/lotto/model/Lotto.kt b/src/main/kotlin/lotto/model/Lotto.kt index 1ddf12bb3..2369d5f7f 100644 --- a/src/main/kotlin/lotto/model/Lotto.kt +++ b/src/main/kotlin/lotto/model/Lotto.kt @@ -1,9 +1,11 @@ package lotto.model +import lotto.util.ExceptionConstants + class Lotto(private val numbers: List) { init { - require(numbers.size == 6) { "[ERROR] 로또 번호는 6개여야 합니다." } + require(numbers.size == 6) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_COUNT } + require(numbers.all { it in 1..45 }) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_RANGE } + require(numbers.distinct().size == 6) { ExceptionConstants.ERROR_DUPLICATE_WINNING_NUMBERS } } - - // TODO: 추가 기능 구현 } \ No newline at end of file From ab4731db5c9029511fa90b8c3ae2ba33adda2f9e Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:12:04 +0900 Subject: [PATCH 08/59] =?UTF-8?q?feat(Lotto.kt):=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=B0=98=ED=99=98=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/model/Lotto.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/model/Lotto.kt b/src/main/kotlin/lotto/model/Lotto.kt index 2369d5f7f..dafd50e62 100644 --- a/src/main/kotlin/lotto/model/Lotto.kt +++ b/src/main/kotlin/lotto/model/Lotto.kt @@ -8,4 +8,8 @@ class Lotto(private val numbers: List) { require(numbers.all { it in 1..45 }) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_RANGE } require(numbers.distinct().size == 6) { ExceptionConstants.ERROR_DUPLICATE_WINNING_NUMBERS } } + + fun getNumbers(): List { + return numbers + } } \ No newline at end of file From b7106be99b8021b38ae510f9f453b42959b2c8db Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:16:55 +0900 Subject: [PATCH 09/59] =?UTF-8?q?feat(Parser.kt):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20=EB=AC=B8=EC=9E=90=EB=93=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20Parser=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=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/parser/Parser.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/parser/Parser.kt diff --git a/src/main/kotlin/lotto/parser/Parser.kt b/src/main/kotlin/lotto/parser/Parser.kt new file mode 100644 index 000000000..ce760ce47 --- /dev/null +++ b/src/main/kotlin/lotto/parser/Parser.kt @@ -0,0 +1,5 @@ +package lotto.parser + +class Parser { + +} \ No newline at end of file From 763a590d0c26399fb0a747aac7fa41117736849d Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:17:51 +0900 Subject: [PATCH 10/59] =?UTF-8?q?feat(Validator.kt):=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?Validator=20=ED=81=B4=EB=9E=98=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/validator/Validator.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/validator/Validator.kt diff --git a/src/main/kotlin/lotto/validator/Validator.kt b/src/main/kotlin/lotto/validator/Validator.kt new file mode 100644 index 000000000..4cc74bc4a --- /dev/null +++ b/src/main/kotlin/lotto/validator/Validator.kt @@ -0,0 +1,5 @@ +package lotto.validator + +class Validator { + +} \ No newline at end of file From 22e1ba85a8b1c65ec88e711a56cb06c8b3bbf48e Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:18:50 +0900 Subject: [PATCH 11/59] =?UTF-8?q?feat(InputView.kt):=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=9E=85=EB=A0=A5=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?InputView=20=ED=81=B4=EB=9E=98=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/view/InputView.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/view/InputView.kt diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt new file mode 100644 index 000000000..6c4b411a3 --- /dev/null +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -0,0 +1,5 @@ +package lotto.view + +class InputView() { + +} \ No newline at end of file From 2d00d741137ec28264346a601a6bdf3cc38c8e1e Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:22:29 +0900 Subject: [PATCH 12/59] =?UTF-8?q?feat(InputView.kt):=20=EA=B5=AC=EC=9E=85?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/kotlin/lotto/view/InputView.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b8d29229..09de8953c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ## 📍 구현할 기능 목록 1. 로또 금액 입력받기 - - [ ] '구입금액을 입력해 주세요.' 메시지 출력 - - [ ] 사용자 입력 받기 + - [x] '구입금액을 입력해 주세요.' 메시지 출력 + - [x] 사용자 입력 받기 - 입력받은 로또 금액 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - [ ] 빈 값을 입력한 경우 - [ ] 양의 정수가 아닌 값을 입력한 경우 diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 6c4b411a3..8779e99ec 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -1,5 +1,13 @@ package lotto.view +import camp.nextstep.edu.missionutils.Console + class InputView() { + fun inputPurchaseAmount(): Int { + while (true) { + println("구입금액을 입력해 주세요.") + val input = Console.readLine() + } + } } \ No newline at end of file From 6ead5e9db9a7d0adbe52009e5d7d6515ab64cd9b Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:29:38 +0900 Subject: [PATCH 13/59] =?UTF-8?q?feat(Validator.kt):=20=EA=B5=AC=EC=9E=85?= =?UTF-8?q?=EA=B8=88=EC=95=A1=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=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 빈값이 들어왔는지, 모두 숫자인지, 0보다 큰 값인지, 1000원 단위인지 검사 --- README.md | 10 +++++----- src/main/kotlin/lotto/util/Constants.kt | 7 +++++++ src/main/kotlin/lotto/util/ExceptionConstants.kt | 5 +++++ src/main/kotlin/lotto/validator/Validator.kt | 13 +++++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/lotto/util/Constants.kt diff --git a/README.md b/README.md index 09de8953c..268fd5f99 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ - [x] '구입금액을 입력해 주세요.' 메시지 출력 - [x] 사용자 입력 받기 - 입력받은 로또 금액 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - - [ ] 빈 값을 입력한 경우 - - [ ] 양의 정수가 아닌 값을 입력한 경우 - - [ ] 숫자가 아닌 값을 입력한 경우 - - [ ] Int 범위를 벗어나는 값을 입력한 경우 - - [ ] 1000원으로 나누어 떨어지지 않는 경우 + - [x] 빈 값을 입력한 경우 + - [x] 양의 정수가 아닌 값을 입력한 경우 + - [x] 숫자가 아닌 값을 입력한 경우 + - [x] Int 범위를 벗어나는 값을 입력한 경우 + - [x] 1000원으로 나누어 떨어지지 않는 경우
diff --git a/src/main/kotlin/lotto/util/Constants.kt b/src/main/kotlin/lotto/util/Constants.kt new file mode 100644 index 000000000..d943240a1 --- /dev/null +++ b/src/main/kotlin/lotto/util/Constants.kt @@ -0,0 +1,7 @@ +package lotto.util + +class Constants { + companion object { + const val LOTTO_UNIT_PRICE = 1000 + } +} \ No newline at end of file diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt index 2c9179b00..1c4731442 100644 --- a/src/main/kotlin/lotto/util/ExceptionConstants.kt +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -5,5 +5,10 @@ class ExceptionConstants { const val ERROR_INVALID_WINNING_NUMBERS_COUNT = "[ERROR] 로또 번호는 6개여야 합니다." const val ERROR_INVALID_WINNING_NUMBERS_RANGE = "[ERROR] 로또 번호는 1부터 45 사이여야 합니다." const val ERROR_DUPLICATE_WINNING_NUMBERS = "[ERROR] 로또 번호는 중복될 수 없습니다." + + const val ERROR_INVALID_PURCHASE_AMOUNT = "[ERROR] 로또는 1,000원 단위로 입력해야 합니다." + const val ERROR_EMPTY_PURCHASE_AMOUNT = "[ERROR] 구매 금액이 비어 있습니다." + const val ERROR_NOT_A_NUMBER = "[ERROR] 구매 금액은 숫자여야 합니다." + const val ERROR_OUT_OF_RANGE = "[ERROR] 구매 금액이 정수의 범위를 벗어납니다." } } \ No newline at end of file diff --git a/src/main/kotlin/lotto/validator/Validator.kt b/src/main/kotlin/lotto/validator/Validator.kt index 4cc74bc4a..aac74f10e 100644 --- a/src/main/kotlin/lotto/validator/Validator.kt +++ b/src/main/kotlin/lotto/validator/Validator.kt @@ -1,5 +1,18 @@ package lotto.validator +import lotto.util.Constants +import lotto.util.ExceptionConstants + class Validator { + fun validatePurchaseAmount(amountString: String) { + require(amountString.isNotBlank()) { ExceptionConstants.ERROR_EMPTY_PURCHASE_AMOUNT } + require(amountString.all { it.isDigit() }) { ExceptionConstants.ERROR_NOT_A_NUMBER } + require(amountString.toBigInteger() <= Int.MAX_VALUE.toBigInteger()) { ExceptionConstants.ERROR_OUT_OF_RANGE } + + val amount = amountString.toInt() + + require(amount > 0) { ExceptionConstants.ERROR_INVALID_PURCHASE_AMOUNT } + require(amount % Constants.LOTTO_UNIT_PRICE == 0) { ExceptionConstants.ERROR_INVALID_PURCHASE_AMOUNT } + } } \ No newline at end of file From b5ca74e4d7be980aeade1ef87c97367b7934d50c Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:30:37 +0900 Subject: [PATCH 14/59] =?UTF-8?q?feat(Parser.kt):=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=EC=9D=84=20=EC=A0=95=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/parser/Parser.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/parser/Parser.kt b/src/main/kotlin/lotto/parser/Parser.kt index ce760ce47..fcc538f34 100644 --- a/src/main/kotlin/lotto/parser/Parser.kt +++ b/src/main/kotlin/lotto/parser/Parser.kt @@ -1,5 +1,7 @@ package lotto.parser class Parser { - + fun parsePurchaseAmount(input: String): Int { + return input.toInt() + } } \ No newline at end of file From b7211283f5cab73894bc673736ee33623f6a05dc Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:31:36 +0900 Subject: [PATCH 15/59] =?UTF-8?q?feat(InputView.kt):=20=EA=B5=AC=EC=9E=85?= =?UTF-8?q?=20=EA=B8=88=EC=95=A1=EC=9D=84=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20=ED=9B=84=20=EC=A0=95=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/view/InputView.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 8779e99ec..fede3cd5c 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -1,13 +1,21 @@ package lotto.view import camp.nextstep.edu.missionutils.Console +import lotto.parser.Parser +import lotto.validator.Validator -class InputView() { +class InputView(private val validator: Validator, private val parser: Parser) { fun inputPurchaseAmount(): Int { while (true) { println("구입금액을 입력해 주세요.") val input = Console.readLine() + validator.validatePurchaseAmount(input) + + val amount = parser.parsePurchaseAmount(input) + println() + + return amount } } } \ No newline at end of file From e1cd8131aea31e53f95bc9c797af5e961fc1f2c2 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:33:36 +0900 Subject: [PATCH 16/59] =?UTF-8?q?feat(InputView.kt):=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=EB=A5=BC=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/kotlin/lotto/view/InputView.kt | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 268fd5f99..7b2c59887 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@
4. 당첨 번호 입력받기 - - [ ] '당첨 번호를 입력해 주세요.' 메시지 출력 - - [ ] 사용자 입력 입력받기 + - [x] '당첨 번호를 입력해 주세요.' 메시지 출력 + - [x] 사용자 입력 입력받기 - 입력받은 당첨 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - [ ] 빈 값을 입력한 경우 - [ ] 구분자로 쉼표를 사용하지 않은 경우 (문자열로 처리해서 에러 발생) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index fede3cd5c..1234ce345 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -18,4 +18,11 @@ class InputView(private val validator: Validator, private val parser: Parser) { return amount } } + + fun inputWinningNumbers(): List { + while (true) { + println("당첨 번호를 입력해 주세요.") + val input = Console.readLine() + } + } } \ No newline at end of file From 7ab7f9ea2ef54b35b0f76fe99e2ef5d5418b4881 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:34:24 +0900 Subject: [PATCH 17/59] =?UTF-8?q?feat(Parser.kt):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=89=BC=ED=91=9C(,)=EB=A1=9C=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/parser/Parser.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/parser/Parser.kt b/src/main/kotlin/lotto/parser/Parser.kt index fcc538f34..454e4e0e3 100644 --- a/src/main/kotlin/lotto/parser/Parser.kt +++ b/src/main/kotlin/lotto/parser/Parser.kt @@ -4,4 +4,8 @@ class Parser { fun parsePurchaseAmount(input: String): Int { return input.toInt() } + + fun parseWinningNumbers(input: String): List { + return input.split(",").map { it.trim().toInt() } + } } \ No newline at end of file From 1cd58ef232eb09ee7805862f94965eae91f8fc66 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:39:16 +0900 Subject: [PATCH 18/59] =?UTF-8?q?feat(Validator.kt):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 빈값을 입력했는지, 6개 값을 모두 입력했는지, 1~45 범위 내에 있는지, 중복되는 값이 있는지 검사 --- README.md | 8 ++++---- src/main/kotlin/lotto/util/Constants.kt | 3 +++ src/main/kotlin/lotto/util/ExceptionConstants.kt | 2 ++ src/main/kotlin/lotto/validator/Validator.kt | 7 +++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7b2c59887..8ec1c15e9 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ - [x] '당첨 번호를 입력해 주세요.' 메시지 출력 - [x] 사용자 입력 입력받기 - 입력받은 당첨 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - - [ ] 빈 값을 입력한 경우 - - [ ] 구분자로 쉼표를 사용하지 않은 경우 (문자열로 처리해서 에러 발생) - - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 - - [ ] 6개보다 적거나 6개를 넘게 입력한 경우 + - [x] 빈 값을 입력한 경우 + - [x] 구분자로 쉼표를 사용하지 않은 경우 (문자열로 처리해서 에러 발생) + - [x] 1 ~ 45 범위를 넘어간 값을 입력한 경우 + - [x] 6개보다 적거나 6개를 넘게 입력한 경우
diff --git a/src/main/kotlin/lotto/util/Constants.kt b/src/main/kotlin/lotto/util/Constants.kt index d943240a1..dd2a049f5 100644 --- a/src/main/kotlin/lotto/util/Constants.kt +++ b/src/main/kotlin/lotto/util/Constants.kt @@ -3,5 +3,8 @@ package lotto.util class Constants { companion object { const val LOTTO_UNIT_PRICE = 1000 + const val MIN_NUMBER = 1 + const val MAX_NUMBER = 45 + const val WINNING_NUMBERS_COUNT = 6 } } \ No newline at end of file diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt index 1c4731442..0abea22ba 100644 --- a/src/main/kotlin/lotto/util/ExceptionConstants.kt +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -10,5 +10,7 @@ class ExceptionConstants { const val ERROR_EMPTY_PURCHASE_AMOUNT = "[ERROR] 구매 금액이 비어 있습니다." const val ERROR_NOT_A_NUMBER = "[ERROR] 구매 금액은 숫자여야 합니다." const val ERROR_OUT_OF_RANGE = "[ERROR] 구매 금액이 정수의 범위를 벗어납니다." + + const val ERROR_EMPTY_WINNING_NUMBERS = "[ERROR] 당첨 번호가 비어 있습니다." } } \ No newline at end of file diff --git a/src/main/kotlin/lotto/validator/Validator.kt b/src/main/kotlin/lotto/validator/Validator.kt index aac74f10e..2084135f0 100644 --- a/src/main/kotlin/lotto/validator/Validator.kt +++ b/src/main/kotlin/lotto/validator/Validator.kt @@ -15,4 +15,11 @@ class Validator { require(amount > 0) { ExceptionConstants.ERROR_INVALID_PURCHASE_AMOUNT } require(amount % Constants.LOTTO_UNIT_PRICE == 0) { ExceptionConstants.ERROR_INVALID_PURCHASE_AMOUNT } } + + fun validateWinningNumbers(numbers: List) { + require(numbers.isNotEmpty()) { ExceptionConstants.ERROR_EMPTY_WINNING_NUMBERS } + require(numbers.size == Constants.WINNING_NUMBERS_COUNT) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_COUNT } + require(numbers.all { it in Constants.MIN_NUMBER..Constants.MAX_NUMBER }) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_RANGE } + require(numbers.distinct().size == Constants.WINNING_NUMBERS_COUNT) { ExceptionConstants.ERROR_DUPLICATE_WINNING_NUMBERS } + } } \ No newline at end of file From 1dfa8a08f0b3f7655ada7c7b210abdf049c257fa Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:40:02 +0900 Subject: [PATCH 19/59] =?UTF-8?q?feat(InputView.kt):=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=ED=9B=84=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/view/InputView.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 1234ce345..803cf89b6 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -23,6 +23,12 @@ class InputView(private val validator: Validator, private val parser: Parser) { while (true) { println("당첨 번호를 입력해 주세요.") val input = Console.readLine() + val numbers = parser.parseWinningNumbers(input) + + validator.validateWinningNumbers(numbers) + println() + + return numbers } } } \ No newline at end of file From e2b8f2a7125531ebcbc3e2b999aaf82abe750567 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:40:46 +0900 Subject: [PATCH 20/59] =?UTF-8?q?feat(InputView.kt):=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=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/kotlin/lotto/view/InputView.kt | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ec1c15e9..ae6baa1bc 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@
5. 보너스 번호 입력받기 - - [ ] '보너스 번호를 입력해 주세요.' 메시지 출력 - - [ ] 사용자 입력받기 + - [x] '보너스 번호를 입력해 주세요.' 메시지 출력 + - [x] 사용자 입력받기 - 입력받은 보너스 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 - [ ] 빈 값을 입력한 경우 diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 803cf89b6..3d8ecaa8b 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -31,4 +31,12 @@ class InputView(private val validator: Validator, private val parser: Parser) { return numbers } } + + fun inputBonusNumber(): Int { + while (true) { + println("보너스 번호를 입력해 주세요.") + val input = Console.readLine() + + } + } } \ No newline at end of file From 5f53211eb8f81f9eb1c156f947637ad8cb5bb998 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:41:38 +0900 Subject: [PATCH 21/59] =?UTF-8?q?feat(Parser.kt):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EB=A5=BC=20=EC=A0=95=EC=88=98=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/parser/Parser.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/parser/Parser.kt b/src/main/kotlin/lotto/parser/Parser.kt index 454e4e0e3..708a097f3 100644 --- a/src/main/kotlin/lotto/parser/Parser.kt +++ b/src/main/kotlin/lotto/parser/Parser.kt @@ -8,4 +8,8 @@ class Parser { fun parseWinningNumbers(input: String): List { return input.split(",").map { it.trim().toInt() } } + + fun parseBonusNumber(input: String): Int { + return input.toInt() + } } \ No newline at end of file From bbd7b6adce9735ad81dde43e26aadb05b3713bf7 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:44:14 +0900 Subject: [PATCH 22/59] =?UTF-8?q?feat(Validator.kt):=20=EB=B3=B4=EB=84=88?= =?UTF-8?q?=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 빈값을 입력했는지, 1~45 범위 내에 있는지, 로또 번호와 중복되는지 유효성 검사 --- README.md | 6 +++--- src/main/kotlin/lotto/util/ExceptionConstants.kt | 5 ++++- src/main/kotlin/lotto/validator/Validator.kt | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ae6baa1bc..d04505abe 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ - [x] '보너스 번호를 입력해 주세요.' 메시지 출력 - [x] 사용자 입력받기 - 입력받은 보너스 번호 유효성 검사 (* `[ERROR]`로 시작하는 에러 문구 출력) - - [ ] 1 ~ 45 범위를 넘어간 값을 입력한 경우 - - [ ] 빈 값을 입력한 경우 - - [ ] 당첨 번호와 중복되는 경우 + - [x] 1 ~ 45 범위를 넘어간 값을 입력한 경우 + - [x] 빈 값을 입력한 경우 + - [x] 당첨 번호와 중복되는 경우
diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt index 0abea22ba..1e1a8437e 100644 --- a/src/main/kotlin/lotto/util/ExceptionConstants.kt +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -5,12 +5,15 @@ class ExceptionConstants { const val ERROR_INVALID_WINNING_NUMBERS_COUNT = "[ERROR] 로또 번호는 6개여야 합니다." const val ERROR_INVALID_WINNING_NUMBERS_RANGE = "[ERROR] 로또 번호는 1부터 45 사이여야 합니다." const val ERROR_DUPLICATE_WINNING_NUMBERS = "[ERROR] 로또 번호는 중복될 수 없습니다." + const val ERROR_EMPTY_WINNING_NUMBERS = "[ERROR] 당첨 번호가 비어 있습니다." const val ERROR_INVALID_PURCHASE_AMOUNT = "[ERROR] 로또는 1,000원 단위로 입력해야 합니다." const val ERROR_EMPTY_PURCHASE_AMOUNT = "[ERROR] 구매 금액이 비어 있습니다." const val ERROR_NOT_A_NUMBER = "[ERROR] 구매 금액은 숫자여야 합니다." const val ERROR_OUT_OF_RANGE = "[ERROR] 구매 금액이 정수의 범위를 벗어납니다." - const val ERROR_EMPTY_WINNING_NUMBERS = "[ERROR] 당첨 번호가 비어 있습니다." + const val ERROR_INVALID_BONUS_NUMBER = "[ERROR] 보너스 번호는 1부터 45 사이여야 합니다." + const val ERROR_DUPLICATE_BONUS_NUMBER = "[ERROR] 보너스 번호가 당첨 번호와 중복됩니다." + const val ERROR_EMPTY_BONUS_NUMBERS = "[ERROR] 보너스 번호가 비어 있습니다." } } \ No newline at end of file diff --git a/src/main/kotlin/lotto/validator/Validator.kt b/src/main/kotlin/lotto/validator/Validator.kt index 2084135f0..39093f153 100644 --- a/src/main/kotlin/lotto/validator/Validator.kt +++ b/src/main/kotlin/lotto/validator/Validator.kt @@ -22,4 +22,10 @@ class Validator { require(numbers.all { it in Constants.MIN_NUMBER..Constants.MAX_NUMBER }) { ExceptionConstants.ERROR_INVALID_WINNING_NUMBERS_RANGE } require(numbers.distinct().size == Constants.WINNING_NUMBERS_COUNT) { ExceptionConstants.ERROR_DUPLICATE_WINNING_NUMBERS } } + + fun validateBonusNumber(bonusNumber: Int, winningNumbers: List) { + require(winningNumbers.isNotEmpty()) { ExceptionConstants.ERROR_EMPTY_BONUS_NUMBERS } + require(bonusNumber in Constants.MIN_NUMBER..Constants.MAX_NUMBER) { ExceptionConstants.ERROR_INVALID_BONUS_NUMBER } + require(bonusNumber !in winningNumbers) { ExceptionConstants.ERROR_DUPLICATE_BONUS_NUMBER } + } } \ No newline at end of file From e4008617c07006ccaf1a609a17b873ef5e1f963e Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:44:44 +0900 Subject: [PATCH 23/59] =?UTF-8?q?feat(InputView.kt):=20=EB=B3=B4=EB=84=88?= =?UTF-8?q?=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20=ED=9B=84=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/view/InputView.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 3d8ecaa8b..850c15635 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -32,11 +32,16 @@ class InputView(private val validator: Validator, private val parser: Parser) { } } - fun inputBonusNumber(): Int { + fun inputBonusNumber(winningNumbers: List): Int { while (true) { println("보너스 번호를 입력해 주세요.") val input = Console.readLine() + val bonusNumber = parser.parseBonusNumber(input) + validator.validateBonusNumber(bonusNumber, winningNumbers) + println() + + return bonusNumber } } } \ No newline at end of file From 4aba21fbd6131ed9cf02631b2225ec0bb93a089a Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:57:08 +0900 Subject: [PATCH 24/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EA=B2=8C=EC=9E=84=20=EC=A7=84=ED=96=89=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=ED=81=B4=EB=9E=98=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/model/LottoGame.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/model/LottoGame.kt diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt new file mode 100644 index 000000000..96d0b92f1 --- /dev/null +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -0,0 +1,5 @@ +package lotto.model + +class LottoGame { + +} \ No newline at end of file From c871f76a94f35780db0e21a4e1672daa74eedc06 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 21:58:00 +0900 Subject: [PATCH 25/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=9E=9C=EB=8D=A4?= =?UTF-8?q?=20=EB=A1=9C=EB=98=90=20=EB=B2=88=ED=98=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/kotlin/lotto/model/LottoGame.kt | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d04505abe..50f300a81 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@
2. 로또 번호 생성 - - [ ] 로또 번호를 생성 - - [ ] `Randoms.pickUniqueNumbersInRange(1, 45, 6)` 이용 + - [x] 로또 번호를 생성 + - [x] `Randoms.pickUniqueNumbersInRange(1, 45, 6)` 이용 - 제공된 `Lotto` 클래스를 사용하여 구현
diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt index 96d0b92f1..f9a4c88ad 100644 --- a/src/main/kotlin/lotto/model/LottoGame.kt +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -1,5 +1,22 @@ package lotto.model +import camp.nextstep.edu.missionutils.Randoms +import lotto.util.Constants + class LottoGame { + fun generateLotto(count: Int): List { + val lotto = List(count) { Lotto(generateRandomNumbers()) } + + return lotto + } + + private fun generateRandomNumbers(): List { + val randomNumbers = Randoms.pickUniqueNumbersInRange( + Constants.MIN_NUMBER, + Constants.MAX_NUMBER, + Constants.WINNING_NUMBERS_COUNT + ) + return randomNumbers + } } \ No newline at end of file From 9dcc29442556af13bc6bdebea8139383cdf52afb Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:00:11 +0900 Subject: [PATCH 26/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EB=8B=B9=EC=B2=A8=20=EA=B3=84=EC=82=B0=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20=ED=95=A8=EC=88=98=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/model/LottoGame.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt index f9a4c88ad..cf2905f8b 100644 --- a/src/main/kotlin/lotto/model/LottoGame.kt +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -19,4 +19,14 @@ class LottoGame { ) return randomNumbers } + + fun calculateResult( + lottos: List, + winningNumbers: List, + bonusNumber: Int + ): LottoResult { + val prizeCounts = Prize.values().associateWith { 0 }.toMutableMap() + var totalPrize = 0 + + } } \ No newline at end of file From 173453ba106fa8aacf738f94aca128b9e345df04 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:01:46 +0900 Subject: [PATCH 27/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=EC=99=80=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9D=BC=EC=B9=98=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/model/LottoGame.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt index cf2905f8b..42e9d76ca 100644 --- a/src/main/kotlin/lotto/model/LottoGame.kt +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -29,4 +29,16 @@ class LottoGame { var totalPrize = 0 } + + private fun calculateMatch( + lotto: Lotto, + winningNumbers: List, + bonusNumber: Int + ): Pair { + val matchCount = lotto.getNumbers().count { it in winningNumbers } + val isBonusMatch = bonusNumber in lotto.getNumbers() && matchCount == 5 + val matchResult = Pair(matchCount, isBonusMatch) + + return matchResult + } } \ No newline at end of file From f0dc8079deeba20c6b3941eda2c370c4eb1e3e3d Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:03:49 +0900 Subject: [PATCH 28/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=20=EB=8B=B9=EC=B2=A8=20=EA=B0=AF=EC=88=98?= =?UTF-8?q?=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/model/LottoGame.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt index 42e9d76ca..a5c55fa91 100644 --- a/src/main/kotlin/lotto/model/LottoGame.kt +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -30,6 +30,20 @@ class LottoGame { } + private fun updatePrizeCounts( + lotto: Lotto, + winningNumbers: List, + bonusNumber: Int, + prizeCounts: MutableMap + ): Int { + val (matchCount, isBonusMatch) = calculateMatch(lotto, winningNumbers, bonusNumber) + val prize = Prize.getPrize(matchCount, isBonusMatch) + prizeCounts[prize] = prizeCounts.getValue(prize) + 1 + val prizeMoney = prize.prizeMoney + + return prizeMoney + } + private fun calculateMatch( lotto: Lotto, winningNumbers: List, From 7d4a129b750ad0d52e66aa073767c3411b2f147d Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:05:16 +0900 Subject: [PATCH 29/59] =?UTF-8?q?feat(LottoGame.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EB=B2=88=ED=98=B8=20=EB=8B=B9=EC=B2=A8=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/model/LottoGame.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/kotlin/lotto/model/LottoGame.kt b/src/main/kotlin/lotto/model/LottoGame.kt index a5c55fa91..adc828894 100644 --- a/src/main/kotlin/lotto/model/LottoGame.kt +++ b/src/main/kotlin/lotto/model/LottoGame.kt @@ -28,6 +28,15 @@ class LottoGame { val prizeCounts = Prize.values().associateWith { 0 }.toMutableMap() var totalPrize = 0 + lottos.forEach { lotto -> + updatePrizeCounts(lotto, winningNumbers, bonusNumber, prizeCounts).also { + totalPrize += it + } + } + + val purchaseAmount = lottos.size * Constants.LOTTO_UNIT_PRICE + + return LottoResult(prizeCounts, totalPrize, purchaseAmount) } private fun updatePrizeCounts( From f6c0c7ab6f29fa4d7d700f3792e698520c44f010 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:07:25 +0900 Subject: [PATCH 30/59] =?UTF-8?q?feat(Prize.kt):=20=EC=83=81=EA=B8=88=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=EC=9D=84=20=EC=9C=84=ED=95=9C=20Prize=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=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/model/Prize.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/kotlin/lotto/model/Prize.kt diff --git a/src/main/kotlin/lotto/model/Prize.kt b/src/main/kotlin/lotto/model/Prize.kt new file mode 100644 index 000000000..b4b40d3db --- /dev/null +++ b/src/main/kotlin/lotto/model/Prize.kt @@ -0,0 +1,12 @@ +package lotto.model + +import lotto.util.Constants + +enum class Prize(val matchCount: Int, val prizeMoney: Int, val bonusMatch: Boolean = false) { + FIRST(6, Constants.FIRST_PRIZE_MONEY), + SECOND(5, Constants.SECOND_PRIZE_MONEY, true), + THIRD(5, Constants.THIRD_PRIZE_MONEY), + FOURTH(4, Constants.FOURTH_PRIZE_MONEY), + FIFTH(3, Constants.FIFTH_PRIZE_MONEY), + NONE(0, 0); +} \ No newline at end of file From 4e47b39ecc5958c9f9d6454334b80ef4209b1b88 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:08:23 +0900 Subject: [PATCH 31/59] =?UTF-8?q?feat(Constants.kt):=20=EC=83=81=EA=B8=88?= =?UTF-8?q?=20=EA=B8=88=EC=95=A1=20=EC=83=81=EC=88=98=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/util/Constants.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/lotto/util/Constants.kt b/src/main/kotlin/lotto/util/Constants.kt index dd2a049f5..49e1699be 100644 --- a/src/main/kotlin/lotto/util/Constants.kt +++ b/src/main/kotlin/lotto/util/Constants.kt @@ -6,5 +6,11 @@ class Constants { const val MIN_NUMBER = 1 const val MAX_NUMBER = 45 const val WINNING_NUMBERS_COUNT = 6 + + const val FIRST_PRIZE_MONEY = 2_000_000_000 + const val SECOND_PRIZE_MONEY = 30_000_000 + const val THIRD_PRIZE_MONEY = 1_500_000 + const val FOURTH_PRIZE_MONEY = 50_000 + const val FIFTH_PRIZE_MONEY = 5_000 } } \ No newline at end of file From 41bdd6f26112f140602e80fea445fb49c716bf33 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:09:09 +0900 Subject: [PATCH 32/59] =?UTF-8?q?feat(Prize.kt):=20=EB=8B=B9=EC=B2=A8=20?= =?UTF-8?q?=EA=B0=AF=EC=88=98=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=93=B1?= =?UTF-8?q?=EC=88=98=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/model/Prize.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/lotto/model/Prize.kt b/src/main/kotlin/lotto/model/Prize.kt index b4b40d3db..3a67dbff9 100644 --- a/src/main/kotlin/lotto/model/Prize.kt +++ b/src/main/kotlin/lotto/model/Prize.kt @@ -9,4 +9,17 @@ enum class Prize(val matchCount: Int, val prizeMoney: Int, val bonusMatch: Boole FOURTH(4, Constants.FOURTH_PRIZE_MONEY), FIFTH(3, Constants.FIFTH_PRIZE_MONEY), NONE(0, 0); + + companion object { + fun getPrize(matchCount: Int, bonusMatch: Boolean): Prize { + return when { + matchCount == 6 -> FIRST + matchCount == 5 && bonusMatch -> SECOND + matchCount == 5 -> THIRD + matchCount == 4 -> FOURTH + matchCount == 3 -> FIFTH + else -> NONE + } + } + } } \ No newline at end of file From 915c0c94d40f47554cf6f773422156639afcbdf2 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:10:32 +0900 Subject: [PATCH 33/59] =?UTF-8?q?feat(LottoResult.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EA=B2=B0=EA=B3=BC=20=EB=B0=98=ED=99=98=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20LottoResult=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=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/model/LottoResult.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/model/LottoResult.kt diff --git a/src/main/kotlin/lotto/model/LottoResult.kt b/src/main/kotlin/lotto/model/LottoResult.kt new file mode 100644 index 000000000..8c8cb76ea --- /dev/null +++ b/src/main/kotlin/lotto/model/LottoResult.kt @@ -0,0 +1,5 @@ +package lotto.model + +data class LottoResult() { + +} \ No newline at end of file From 419212a6bcd684f7d241076843048911503cbd5b Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:13:04 +0900 Subject: [PATCH 34/59] =?UTF-8?q?feat(LottoResult.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EA=B2=B0=EA=B3=BC=20=EC=88=98=EC=9D=B5=EB=A5=A0=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 수익률은 '당첨금액 / 구입금액 * 100'으로 계산, 결과값은 소수점 둘째 자리에서 반올림 --- README.md | 4 ++-- src/main/kotlin/lotto/model/LottoResult.kt | 19 ++++++++++++++++++- src/main/kotlin/lotto/util/Constants.kt | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 50f300a81..c9deb9341 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@
7. 수익률 출력하기 - - [ ] `당첨금액 / 구입금액 * 100` 으로 수익률 계산 - - [ ] 수익률 결과값은 소수점 둘째 자리에서 반올림 + - [x] `당첨금액 / 구입금액 * 100` 으로 수익률 계산 + - [x] 수익률 결과값은 소수점 둘째 자리에서 반올림
diff --git a/src/main/kotlin/lotto/model/LottoResult.kt b/src/main/kotlin/lotto/model/LottoResult.kt index 8c8cb76ea..c11d7ab3c 100644 --- a/src/main/kotlin/lotto/model/LottoResult.kt +++ b/src/main/kotlin/lotto/model/LottoResult.kt @@ -1,5 +1,22 @@ package lotto.model -data class LottoResult() { +import lotto.util.Constants +data class LottoResult( + val prizeCounts: Map, + val totalPrize: Int, + val purchaseAmount: Int +) { + val profitRate: Double + get() { + if (purchaseAmount > 0) { + return (totalPrize.toDouble() / purchaseAmount * Constants.PERCENTAGE_MULTIPLIER) + .roundToTwoDecimalPlaces() + } + return 0.0 + } + + private fun Double.roundToTwoDecimalPlaces(): Double { + return String.format("%.2f", this).toDouble() + } } \ No newline at end of file diff --git a/src/main/kotlin/lotto/util/Constants.kt b/src/main/kotlin/lotto/util/Constants.kt index 49e1699be..9ed726eb2 100644 --- a/src/main/kotlin/lotto/util/Constants.kt +++ b/src/main/kotlin/lotto/util/Constants.kt @@ -6,6 +6,7 @@ class Constants { const val MIN_NUMBER = 1 const val MAX_NUMBER = 45 const val WINNING_NUMBERS_COUNT = 6 + const val PERCENTAGE_MULTIPLIER = 100 const val FIRST_PRIZE_MONEY = 2_000_000_000 const val SECOND_PRIZE_MONEY = 30_000_000 From e78100744aede14020eaca6b960be8c3114e2434 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:14:59 +0900 Subject: [PATCH 35/59] =?UTF-8?q?feat(ResultView.kt):=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EA=B0=92=20=EC=B6=9C=EB=A0=A5=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?ResultView=20=ED=81=B4=EB=9E=98=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/view/ResultView.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/view/ResultView.kt diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt new file mode 100644 index 000000000..99970a02c --- /dev/null +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -0,0 +1,5 @@ +package lotto.view + +class ResultView { + +} \ No newline at end of file From 66defe786686061ddf33bc55643bf4b367c0836e Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:15:45 +0900 Subject: [PATCH 36/59] =?UTF-8?q?feat(ResultView.kt):=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=ED=95=9C=20=EB=A1=9C=EB=98=90=20=EA=B0=9C=EC=88=98=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/lotto/view/ResultView.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9deb9341..05bc2e1a4 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@
3. 발행한 로또 수량 및 번호 출력 - - [ ] 입력한 금액만큼 발행한 로또 수량 출력 + - [x] 입력한 금액만큼 발행한 로또 수량 출력 - [ ] 수량만큼 발행된 번호 출력
diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt index 99970a02c..f8ed5a878 100644 --- a/src/main/kotlin/lotto/view/ResultView.kt +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -1,5 +1,15 @@ package lotto.view +import lotto.model.Lotto + class ResultView { + fun displayPurchasedLotto(lottoCount: Int, lottos: List) { + println("${lottoCount}개를 구매했습니다.") + + lottos.forEach { lotto -> + println(lotto.getNumbers()) + } + println() + } } \ No newline at end of file From 5737f3cd9a4182b8eb3fe6dc8b70b9e45042a956 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:16:27 +0900 Subject: [PATCH 37/59] =?UTF-8?q?feat(ResultView.kt):=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=20=ED=86=B5=EA=B3=84=20=EC=95=88=EB=82=B4=20=EB=AC=B8=EA=B5=AC?= =?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/view/ResultView.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt index f8ed5a878..138aa5a7d 100644 --- a/src/main/kotlin/lotto/view/ResultView.kt +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -12,4 +12,9 @@ class ResultView { } println() } + + private fun displayTitle() { + println("당첨 통계") + println("---") + } } \ No newline at end of file From 4745f771341798f96290b068f98eae7d5c66b600 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:20:09 +0900 Subject: [PATCH 38/59] =?UTF-8?q?feat(ResultView.kt):=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=20=ED=86=B5=EA=B3=84=20=EB=82=B4=EC=9A=A9=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- src/main/kotlin/lotto/view/ResultView.kt | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 05bc2e1a4..502785803 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@
6. 당첨 내역 출력하기 - - [ ] 당첨금은 3자리 마다 쉼표(,)로 구분 - - [ ] 3개부터 6까지 일치하는 내역 계산 - - [ ] 당첨 내역 출력 + - [x] 당첨금은 3자리 마다 쉼표(,)로 구분 + - [x] 3개부터 6까지 일치하는 내역 계산 + - [x] 당첨 내역 출력
diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt index 138aa5a7d..fc76a87f9 100644 --- a/src/main/kotlin/lotto/view/ResultView.kt +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -1,6 +1,10 @@ package lotto.view import lotto.model.Lotto +import lotto.model.LottoResult +import lotto.model.Prize +import java.text.NumberFormat +import java.util.Locale class ResultView { @@ -17,4 +21,18 @@ class ResultView { println("당첨 통계") println("---") } + + private fun displayPrizes(lottoResult: LottoResult) { + Prize.entries + .filter { it != Prize.NONE } + .sortedWith(compareBy({ it.matchCount }, { it.bonusMatch })) + .forEach { prize -> + val count = lottoResult.prizeCounts.getOrDefault(prize, 0) + val bonusText = if (prize.bonusMatch) ", 보너스 볼 일치" else "" + val formattedPrizeMoney = + NumberFormat.getNumberInstance(Locale.KOREA).format(prize.prizeMoney) + + println("${prize.matchCount}개 일치${bonusText} (${formattedPrizeMoney}원) - ${count}개") + } + } } \ No newline at end of file From 1866c4d8c9c1fb65fb56c24048a21f2ee5412998 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:21:27 +0900 Subject: [PATCH 39/59] =?UTF-8?q?feat(ResultView.kt):=20=EC=88=98=EC=9D=B5?= =?UTF-8?q?=EB=A5=A0=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/view/ResultView.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt index fc76a87f9..763336726 100644 --- a/src/main/kotlin/lotto/view/ResultView.kt +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -35,4 +35,8 @@ class ResultView { println("${prize.matchCount}개 일치${bonusText} (${formattedPrizeMoney}원) - ${count}개") } } + + private fun displayProfitRate(lottoResult: LottoResult) { + println("총 수익률은 ${lottoResult.profitRate}%입니다.") + } } \ No newline at end of file From 5fcf7e92be38e90e34935d55d87e7347e31f17cd Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:22:06 +0900 Subject: [PATCH 40/59] =?UTF-8?q?feat(ResultView.kt):=20=EB=B3=B4=EC=97=AC?= =?UTF-8?q?=EC=A4=84=20=EA=B2=B0=EA=B3=BC=EB=93=A4=EC=9D=84=20=EB=8F=99?= =?UTF-8?q?=EC=8B=9C=EC=97=90=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/view/ResultView.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/lotto/view/ResultView.kt b/src/main/kotlin/lotto/view/ResultView.kt index 763336726..7e146eb40 100644 --- a/src/main/kotlin/lotto/view/ResultView.kt +++ b/src/main/kotlin/lotto/view/ResultView.kt @@ -17,6 +17,12 @@ class ResultView { println() } + fun displayResult(lottoResult: LottoResult) { + displayTitle() + displayPrizes(lottoResult) + displayProfitRate(lottoResult) + } + private fun displayTitle() { println("당첨 통계") println("---") From 383a97c7760ee20047f182be287b1f518209e085 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:24:11 +0900 Subject: [PATCH 41/59] =?UTF-8?q?feat(LottoController.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20LottoController=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=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/controller/LottoController.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/kotlin/lotto/controller/LottoController.kt diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt new file mode 100644 index 000000000..a4a000e98 --- /dev/null +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -0,0 +1,5 @@ +package lotto.controller + +class LottoController { + +} \ No newline at end of file From 7d2249da55731edce43bddd16ab4bf091b7bfea3 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:25:51 +0900 Subject: [PATCH 42/59] =?UTF-8?q?feat(LottoController.kt):=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/controller/LottoController.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index a4a000e98..8710b7524 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -1,5 +1,16 @@ package lotto.controller +import lotto.parser.Parser +import lotto.validator.Validator +import lotto.view.InputView + class LottoController { + private val validator = Validator() + private val parser = Parser() + private val inputView = InputView(validator, parser) + + fun start() { + val purchaseAmount = inputView.inputPurchaseAmount() + } } \ No newline at end of file From f533e13e8cb0cb53dca21b8886d2c46da4a8f251 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:26:38 +0900 Subject: [PATCH 43/59] =?UTF-8?q?feat(LottoController.kt):=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EA=B0=80=EB=8A=A5=ED=95=9C=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/controller/LottoController.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index 8710b7524..29adf982e 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -1,6 +1,7 @@ package lotto.controller import lotto.parser.Parser +import lotto.util.Constants import lotto.validator.Validator import lotto.view.InputView @@ -11,6 +12,6 @@ class LottoController { fun start() { val purchaseAmount = inputView.inputPurchaseAmount() - + val lottoCount = purchaseAmount / Constants.LOTTO_UNIT_PRICE } } \ No newline at end of file From df2e65ffbc4612a525bd99bb0e223766d0ff2879 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:27:07 +0900 Subject: [PATCH 44/59] =?UTF-8?q?feat(LottoController.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EB=B2=88=ED=98=B8=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/controller/LottoController.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index 29adf982e..27641048d 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -1,5 +1,6 @@ package lotto.controller +import lotto.model.LottoGame import lotto.parser.Parser import lotto.util.Constants import lotto.validator.Validator @@ -9,9 +10,11 @@ class LottoController { private val validator = Validator() private val parser = Parser() private val inputView = InputView(validator, parser) + private val lottoGame = LottoGame() fun start() { val purchaseAmount = inputView.inputPurchaseAmount() val lottoCount = purchaseAmount / Constants.LOTTO_UNIT_PRICE + val lottos = lottoGame.generateLotto(lottoCount) } } \ No newline at end of file From fe60b650b47ef3c1e8bcbfa130f9dd0ce607baf7 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:27:50 +0900 Subject: [PATCH 45/59] =?UTF-8?q?feat(LottoController.kt):=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EB=90=9C=20=EB=9E=9C=EB=8D=A4=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=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/controller/LottoController.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index 27641048d..116ec9562 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -5,16 +5,20 @@ import lotto.parser.Parser import lotto.util.Constants import lotto.validator.Validator import lotto.view.InputView +import lotto.view.ResultView class LottoController { private val validator = Validator() private val parser = Parser() private val inputView = InputView(validator, parser) + private val resultView = ResultView() private val lottoGame = LottoGame() fun start() { val purchaseAmount = inputView.inputPurchaseAmount() val lottoCount = purchaseAmount / Constants.LOTTO_UNIT_PRICE val lottos = lottoGame.generateLotto(lottoCount) + + resultView.displayPurchasedLotto(lottoCount, lottos) } } \ No newline at end of file From b8e83f11f16ce003134ebd1c64336d11cccbc8c2 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:28:10 +0900 Subject: [PATCH 46/59] =?UTF-8?q?feat(LottoController.kt):=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/controller/LottoController.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index 116ec9562..b9e714c2a 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -20,5 +20,7 @@ class LottoController { val lottos = lottoGame.generateLotto(lottoCount) resultView.displayPurchasedLotto(lottoCount, lottos) + + val winningNumbers = inputView.inputWinningNumbers() } } \ No newline at end of file From 37bd82ebc6187a8f005e6a84087cf4c964d99481 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:28:21 +0900 Subject: [PATCH 47/59] =?UTF-8?q?feat(LottoController.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?=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/controller/LottoController.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index b9e714c2a..c6e30d043 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -22,5 +22,6 @@ class LottoController { resultView.displayPurchasedLotto(lottoCount, lottos) val winningNumbers = inputView.inputWinningNumbers() + val bonusNumber = inputView.inputBonusNumber(winningNumbers) } } \ No newline at end of file From 5740c4440e283afe438b8bfc1ceb1a9fbb4d1725 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:28:45 +0900 Subject: [PATCH 48/59] =?UTF-8?q?feat(LottoController.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EA=B2=B0=EA=B3=BC=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/controller/LottoController.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index c6e30d043..1bd87fae8 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -23,5 +23,6 @@ class LottoController { val winningNumbers = inputView.inputWinningNumbers() val bonusNumber = inputView.inputBonusNumber(winningNumbers) + val lottoResult = lottoGame.calculateResult(lottos, winningNumbers, bonusNumber) } } \ No newline at end of file From 5df1b7e02e409931957061859d0cc5c2ce510661 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:29:05 +0900 Subject: [PATCH 49/59] =?UTF-8?q?feat(LottoController.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/lotto/controller/LottoController.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 502785803..60044f821 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ 3. 발행한 로또 수량 및 번호 출력 - [x] 입력한 금액만큼 발행한 로또 수량 출력 - - [ ] 수량만큼 발행된 번호 출력 + - [x] 수량만큼 발행된 번호 출력
diff --git a/src/main/kotlin/lotto/controller/LottoController.kt b/src/main/kotlin/lotto/controller/LottoController.kt index 1bd87fae8..dec4cfe3a 100644 --- a/src/main/kotlin/lotto/controller/LottoController.kt +++ b/src/main/kotlin/lotto/controller/LottoController.kt @@ -24,5 +24,7 @@ class LottoController { val winningNumbers = inputView.inputWinningNumbers() val bonusNumber = inputView.inputBonusNumber(winningNumbers) val lottoResult = lottoGame.calculateResult(lottos, winningNumbers, bonusNumber) + + resultView.displayResult(lottoResult) } } \ No newline at end of file From 2d342e9c43f2311e0698565a703779ca698d0d62 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:29:31 +0900 Subject: [PATCH 50/59] =?UTF-8?q?feat(Application.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/Application.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 151821c9c..25a655b14 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -1,5 +1,7 @@ package lotto +import lotto.controller.LottoController + fun main() { - // TODO: 프로그램 구현 + LottoController().start() } From 45627a24d8d2a3f5056c7973ee683655236849f4 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:30:04 +0900 Subject: [PATCH 51/59] =?UTF-8?q?test(LottoTest.kt):=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=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 --- src/test/kotlin/lotto/{ => model}/LottoTest.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) rename src/test/kotlin/lotto/{ => model}/LottoTest.kt (70%) diff --git a/src/test/kotlin/lotto/LottoTest.kt b/src/test/kotlin/lotto/model/LottoTest.kt similarity index 70% rename from src/test/kotlin/lotto/LottoTest.kt rename to src/test/kotlin/lotto/model/LottoTest.kt index 122fae572..75cf3cd37 100644 --- a/src/test/kotlin/lotto/LottoTest.kt +++ b/src/test/kotlin/lotto/model/LottoTest.kt @@ -1,4 +1,4 @@ -package lotto +package lotto.model import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -11,7 +11,6 @@ class LottoTest { } } - // TODO: 테스트가 통과하도록 프로덕션 코드 구현 @Test fun `로또 번호에 중복된 숫자가 있으면 예외가 발생한다`() { assertThrows { @@ -19,5 +18,10 @@ class LottoTest { } } - // TODO: 추가 기능 구현에 따른 테스트 코드 작성 -} + @Test + fun `로또 번호가 범위를 벗어나면 예외가 발생한다`() { + assertThrows { + Lotto(listOf(0, 1, 2, 3, 4, 5)) + } + } +} \ No newline at end of file From 1baced41f87a4e3064ce6e21689b69a288ac9c12 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:30:28 +0900 Subject: [PATCH 52/59] =?UTF-8?q?test(LottoGameTest.kt):=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EC=A7=84=ED=96=89=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/lotto/model/LottoGameTest.kt | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/kotlin/lotto/model/LottoGameTest.kt diff --git a/src/test/kotlin/lotto/model/LottoGameTest.kt b/src/test/kotlin/lotto/model/LottoGameTest.kt new file mode 100644 index 000000000..5c91ea0e3 --- /dev/null +++ b/src/test/kotlin/lotto/model/LottoGameTest.kt @@ -0,0 +1,54 @@ +package lotto.model + +import lotto.util.Constants +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class LottoGameTest { + + private val lottoGame = LottoGame() + + @Test + fun `로또 번호를 생성할 때 지정된 개수의 로또를 생성해야 한다`() { + val lottoCount = 5 + val lottos = lottoGame.generateLotto(lottoCount) + + assertEquals(lottoCount, lottos.size) + lottos.forEach { lotto -> + assertEquals(6, lotto.getNumbers().size) + lotto.getNumbers().forEach { number -> + assert(number in 1..45) { "번호는 1에서 45 사이여야 합니다." } + } + } + } + + @Test + fun `로또 결과를 계산할 때 당첨금이 올바르게 계산되어야 한다`() { + val lottos = listOf( + Lotto(listOf(1, 2, 3, 4, 5, 6)), + Lotto(listOf(1, 2, 3, 4, 5, 7)), + Lotto(listOf(1, 2, 3, 4, 5, 9)), + Lotto(listOf(1, 2, 3, 4, 11, 12)), + Lotto(listOf(1, 2, 3, 16, 17, 18)), + Lotto(listOf(19, 20, 21, 22, 23, 24)) + ) + + val winningNumbers = listOf(1, 2, 3, 4, 5,6) + val bonusNumber = 7 + + val result: LottoResult = lottoGame.calculateResult(lottos, winningNumbers, bonusNumber) + + val expectedPrizeCounts = mapOf( + Prize.FIRST to 1, + Prize.SECOND to 1, + Prize.THIRD to 1, + Prize.FOURTH to 1, + Prize.FIFTH to 1, + Prize.NONE to 1 + ) + + assertEquals(expectedPrizeCounts, result.prizeCounts) + assertEquals(2031555000, result.totalPrize) + assertEquals(lottos.size * Constants.LOTTO_UNIT_PRICE, result.purchaseAmount) + } +} \ No newline at end of file From a965acf0b76dd0e8b28ffdb66793c1b6099479a7 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:30:53 +0900 Subject: [PATCH 53/59] =?UTF-8?q?test(LottoResultTest.kt):=20=EC=88=98?= =?UTF-8?q?=EC=9D=B5=EB=A5=A0=20=EA=B3=84=EC=82=B0=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 --- .../kotlin/lotto/model/LottoResultTest.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/kotlin/lotto/model/LottoResultTest.kt diff --git a/src/test/kotlin/lotto/model/LottoResultTest.kt b/src/test/kotlin/lotto/model/LottoResultTest.kt new file mode 100644 index 000000000..102e70ee9 --- /dev/null +++ b/src/test/kotlin/lotto/model/LottoResultTest.kt @@ -0,0 +1,22 @@ +package lotto.model + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class LottoResultTest { + + @Test + fun `profitRate 계산이 올바르게 이루어져야 한다`() { + val prizeCounts = mapOf( + Prize.FIRST to 1, + Prize.SECOND to 0, + Prize.THIRD to 0 + ) + val totalPrize = 2000000 + val purchaseAmount = 1000 + + val result = LottoResult(prizeCounts, totalPrize, purchaseAmount) + + assertEquals(199900.0, result.profitRate) + } +} \ No newline at end of file From 8e7b59b80ccefc0db82648090dfe0935c7aa1a78 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:31:05 +0900 Subject: [PATCH 54/59] =?UTF-8?q?test(ParserTest.kt):=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=20=EB=B0=8F=20=EB=B6=84=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/lotto/parser/ParserTest.kt | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/test/kotlin/lotto/parser/ParserTest.kt diff --git a/src/test/kotlin/lotto/parser/ParserTest.kt b/src/test/kotlin/lotto/parser/ParserTest.kt new file mode 100644 index 000000000..b5dce5b7a --- /dev/null +++ b/src/test/kotlin/lotto/parser/ParserTest.kt @@ -0,0 +1,55 @@ +package lotto.parser + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class ParserTest { + + private val parser = Parser() + + @Test + fun `구입금액이 정상적으로 파싱된다`() { + val input = "1000" + val result = parser.parsePurchaseAmount(input) + assertEquals(1000, result) + } + + @Test + fun `당첨 번호가 정상적으로 파싱된다`() { + val input = "1,2,3,4,5,6" + val result = parser.parseWinningNumbers(input) + assertEquals(listOf(1, 2, 3, 4, 5, 6), result) + } + + @Test + fun `보너스 번호가 정상적으로 파싱된다`() { + val input = "7" + val result = parser.parseBonusNumber(input) + assertEquals(7, result) + } + + @Test + fun `구입금액이 숫자가 아닌 경우 예외가 발생한다`() { + val input = "천" + assertThrows { + parser.parsePurchaseAmount(input) + } + } + + @Test + fun `당첨 번호에서 숫자가 아닌 값이 포함된 경우 예외가 발생한다`() { + val input = "1, 2, a, 4, 5, 6" + assertThrows { + parser.parseWinningNumbers(input) + } + } + + @Test + fun `보너스 번호가 숫자가 아닌 경우 예외가 발생한다`() { + val input = "일" + assertThrows { + parser.parseBonusNumber(input) + } + } +} \ No newline at end of file From 93267bcc6b901c328cae25791dc23c71a6d05270 Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:31:21 +0900 Subject: [PATCH 55/59] =?UTF-8?q?test(PrizeTest.kt):=20=EC=83=81=EA=B8=88?= =?UTF-8?q?=20=EB=B0=98=ED=99=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/lotto/model/PrizeTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/kotlin/lotto/model/PrizeTest.kt diff --git a/src/test/kotlin/lotto/model/PrizeTest.kt b/src/test/kotlin/lotto/model/PrizeTest.kt new file mode 100644 index 000000000..1c8d0806c --- /dev/null +++ b/src/test/kotlin/lotto/model/PrizeTest.kt @@ -0,0 +1,17 @@ +package lotto.model + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class PrizeTest { + + @Test + fun `getPrize 메소드가 올바른 상금을 반환해야 한다`() { + assertEquals(Prize.FIRST, Prize.getPrize(6, false)) + assertEquals(Prize.SECOND, Prize.getPrize(5, true)) + assertEquals(Prize.THIRD, Prize.getPrize(5, false)) + assertEquals(Prize.FOURTH, Prize.getPrize(4, false)) + assertEquals(Prize.FIFTH, Prize.getPrize(3, false)) + assertEquals(Prize.NONE, Prize.getPrize(0, false)) + } +} \ No newline at end of file From 2ca4b77a79cd444f4e8a6279c80aa3159c56faef Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 22:31:42 +0900 Subject: [PATCH 56/59] =?UTF-8?q?test(ValidatorTest.kt):=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=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 --- README.md | 2 +- .../kotlin/lotto/validator/ValidatorTest.kt | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/lotto/validator/ValidatorTest.kt diff --git a/README.md b/README.md index 60044f821..c55057080 100644 --- a/README.md +++ b/README.md @@ -61,4 +61,4 @@
8. 단위 테스트 진행하기 - - [ ] 구현한 기능에 대한 단위 테스트 진행 \ No newline at end of file + - [x] 구현한 기능에 대한 단위 테스트 진행 \ No newline at end of file diff --git a/src/test/kotlin/lotto/validator/ValidatorTest.kt b/src/test/kotlin/lotto/validator/ValidatorTest.kt new file mode 100644 index 000000000..53723b80f --- /dev/null +++ b/src/test/kotlin/lotto/validator/ValidatorTest.kt @@ -0,0 +1,58 @@ +package lotto.validator + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class ValidatorTest { + + private val validator = Validator() + + @Test + fun `구매 금액이 로또 단위 금액이 아니면 예외가 발생한다`() { + assertThrows { + validator.validatePurchaseAmount(1500.toString()) + } + } + + @Test + fun `구매 금액이 0일 때 예외가 발생한다`() { + assertThrows { + validator.validatePurchaseAmount(0.toString()) + } + } + + @Test + fun `당첨 번호의 개수가 6개가 아니면 예외가 발생한다`() { + assertThrows { + validator.validateWinningNumbers(listOf(1, 2, 3, 4, 5)) + } + } + + @Test + fun `당첨 번호가 범위를 벗어나면 예외가 발생한다`() { + assertThrows { + validator.validateWinningNumbers(listOf(0, 1, 2, 3, 4, 5)) + } + } + + @Test + fun `당첨 번호에 중복된 숫자가 있으면 예외가 발생한다`() { + assertThrows { + validator.validateWinningNumbers(listOf(1, 2, 3, 3, 4, 5)) + } + } + + @Test + fun `보너스 번호가 범위를 벗어나면 예외가 발생한다`() { + assertThrows { + validator.validateBonusNumber(0, listOf(1, 2, 3, 4, 5, 6)) + } + } + + @Test + fun `보너스 번호가 당첨 번호와 중복되면 예외가 발생한다`() { + assertThrows { + validator.validateBonusNumber(1, listOf(1, 2, 3, 4, 5, 6)) + } + } +} \ No newline at end of file From cbe81ea07b818ba85cc7a06a1f1f9904147c537b Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 23:28:40 +0900 Subject: [PATCH 57/59] =?UTF-8?q?refactor(InputView.kt):=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EA=B0=92=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=ED=9B=84=20=EC=97=90=EB=9F=AC=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=BD=98=EC=86=94=EC=97=90=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/view/InputView.kt | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 850c15635..275cdcfbc 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -10,7 +10,12 @@ class InputView(private val validator: Validator, private val parser: Parser) { while (true) { println("구입금액을 입력해 주세요.") val input = Console.readLine() - validator.validatePurchaseAmount(input) + try { + validator.validatePurchaseAmount(input) + } catch (e: IllegalArgumentException) { + println(e.message) + throw e + } val amount = parser.parsePurchaseAmount(input) println() @@ -25,7 +30,12 @@ class InputView(private val validator: Validator, private val parser: Parser) { val input = Console.readLine() val numbers = parser.parseWinningNumbers(input) - validator.validateWinningNumbers(numbers) + try { + validator.validateWinningNumbers(numbers) + } catch (e: IllegalArgumentException) { + println(e.message) + throw e + } println() return numbers @@ -38,7 +48,12 @@ class InputView(private val validator: Validator, private val parser: Parser) { val input = Console.readLine() val bonusNumber = parser.parseBonusNumber(input) - validator.validateBonusNumber(bonusNumber, winningNumbers) + try { + validator.validateBonusNumber(bonusNumber, winningNumbers) + } catch (e: IllegalArgumentException) { + println(e.message) + throw e + } println() return bonusNumber From 032f116d5bced8a541efc12e2b3ab30506f9beca Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 23:45:13 +0900 Subject: [PATCH 58/59] =?UTF-8?q?feat(Parser.kt):=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=EC=9E=90=EA=B0=80=20=EC=89=BC=ED=91=9C=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=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 --- src/main/kotlin/lotto/parser/Parser.kt | 7 ++++++- src/main/kotlin/lotto/util/ExceptionConstants.kt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/lotto/parser/Parser.kt b/src/main/kotlin/lotto/parser/Parser.kt index 708a097f3..833e4ab37 100644 --- a/src/main/kotlin/lotto/parser/Parser.kt +++ b/src/main/kotlin/lotto/parser/Parser.kt @@ -1,12 +1,17 @@ package lotto.parser +import lotto.util.ExceptionConstants + class Parser { fun parsePurchaseAmount(input: String): Int { return input.toInt() } fun parseWinningNumbers(input: String): List { - return input.split(",").map { it.trim().toInt() } + val delimiter = "," + require(input.contains(delimiter)) { ExceptionConstants.ERROR_INVALID_DELIMITER } + + return input.split(delimiter).map { it.trim().toInt() } } fun parseBonusNumber(input: String): Int { diff --git a/src/main/kotlin/lotto/util/ExceptionConstants.kt b/src/main/kotlin/lotto/util/ExceptionConstants.kt index 1e1a8437e..c8baa90e8 100644 --- a/src/main/kotlin/lotto/util/ExceptionConstants.kt +++ b/src/main/kotlin/lotto/util/ExceptionConstants.kt @@ -6,6 +6,7 @@ class ExceptionConstants { const val ERROR_INVALID_WINNING_NUMBERS_RANGE = "[ERROR] 로또 번호는 1부터 45 사이여야 합니다." const val ERROR_DUPLICATE_WINNING_NUMBERS = "[ERROR] 로또 번호는 중복될 수 없습니다." const val ERROR_EMPTY_WINNING_NUMBERS = "[ERROR] 당첨 번호가 비어 있습니다." + const val ERROR_INVALID_DELIMITER = "[ERROR] 당첨 번호는 쉼표(,)로 구분해야 합니다." const val ERROR_INVALID_PURCHASE_AMOUNT = "[ERROR] 로또는 1,000원 단위로 입력해야 합니다." const val ERROR_EMPTY_PURCHASE_AMOUNT = "[ERROR] 구매 금액이 비어 있습니다." From b68d85447734865131c3168ad5c895ace652960a Mon Sep 17 00:00:00 2001 From: Jieun Date: Mon, 4 Nov 2024 23:45:43 +0900 Subject: [PATCH 59/59] =?UTF-8?q?refactor(InputView.kt):=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EA=B0=80=20=EB=B0=9C=EC=83=9D=ED=95=98=EB=A9=B4=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/view/InputView.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/lotto/view/InputView.kt b/src/main/kotlin/lotto/view/InputView.kt index 275cdcfbc..3b3d2c1e8 100644 --- a/src/main/kotlin/lotto/view/InputView.kt +++ b/src/main/kotlin/lotto/view/InputView.kt @@ -14,7 +14,7 @@ class InputView(private val validator: Validator, private val parser: Parser) { validator.validatePurchaseAmount(input) } catch (e: IllegalArgumentException) { println(e.message) - throw e + continue } val amount = parser.parsePurchaseAmount(input) @@ -28,17 +28,16 @@ class InputView(private val validator: Validator, private val parser: Parser) { while (true) { println("당첨 번호를 입력해 주세요.") val input = Console.readLine() - val numbers = parser.parseWinningNumbers(input) try { + val numbers = parser.parseWinningNumbers(input) validator.validateWinningNumbers(numbers) + println() + return numbers } catch (e: IllegalArgumentException) { println(e.message) - throw e + continue } - println() - - return numbers } } @@ -52,7 +51,7 @@ class InputView(private val validator: Validator, private val parser: Parser) { validator.validateBonusNumber(bonusNumber, winningNumbers) } catch (e: IllegalArgumentException) { println(e.message) - throw e + continue } println()