From fc4d9d9e8b7b746f9b342d49c7eea3ce2a35d621 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sat, 4 Nov 2023 16:00:46 +0900 Subject: [PATCH 01/53] =?UTF-8?q?docs=20:=20=EA=B8=B0=EB=8A=A5=20=EC=9A=94?= =?UTF-8?q?=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/readme.md | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 docs/readme.md diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000000..f5f183aa76 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,152 @@ +## 기능 요구 사항 + + 로또 게임 기능을 구현해야 한다. 로또 게임은 아래와 같은 규칙으로 진행된다. + +``` +- 로또 번호의 숫자 범위는 1~45까지이다. +- 1개의 로또를 발행할 때 중복되지 않는 6개의 숫자를 뽑는다. +- 당첨 번호 추첨 시 중복되지 않는 숫자 6개와 보너스 번호 1개를 뽑는다. +- 당첨은 1등부터 5등까지 있다. 당첨 기준과 금액은 아래와 같다. + - 1등: 6개 번호 일치 / 2,000,000,000원 + - 2등: 5개 번호 + 보너스 번호 일치 / 30,000,000원 + - 3등: 5개 번호 일치 / 1,500,000원 + - 4등: 4개 번호 일치 / 50,000원 + - 5등: 3개 번호 일치 / 5,000원 +``` + +- 로또 구입 금액을 입력하면 구입 금액에 해당하는 만큼 로또를 발행해야 한다. +- 로또 1장의 가격은 1,000원이다. +- 당첨 번호와 보너스 번호를 입력받는다. +- 사용자가 구매한 로또 번호와 당첨 번호를 비교하여 당첨 내역 및 수익률을 출력하고 로또 게임을 종료한다. +- 사용자가 잘못된 값을 입력할 경우 `throw`문을 사용해 예외를 발생시킨다. 그런 다음, "[ERROR]"로 시작하는 에러 메시지를 출력하고 해당 부분부터 입력을 다시 받는다. + ``` + 예시) [ERROR] 숫자가 잘못된 형식입니다. + ``` + +### 입출력 요구 사항 + +#### 입력 + +- 로또 구입 금액을 입력 받는다. 구입 금액은 1,000원 단위로 입력 받으며 1,000원으로 나누어 떨어지지 않는 경우 예외 처리한다. + +``` +14000 +``` + +- 당첨 번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다. + +``` +1,2,3,4,5,6 +``` + +- 보너스 번호를 입력 받는다. + +``` +7 +``` + +#### 출력 + +- 발행한 로또 수량 및 번호를 출력한다. 로또 번호는 오름차순으로 정렬하여 보여준다. + +``` +8개를 구매했습니다. +[8, 21, 23, 41, 42, 43] +[3, 5, 11, 16, 32, 38] +[7, 11, 16, 35, 36, 44] +[1, 8, 11, 31, 41, 42] +[13, 14, 16, 38, 42, 45] +[7, 11, 30, 40, 42, 43] +[2, 13, 22, 32, 38, 45] +[1, 3, 5, 14, 22, 45] +``` + +- 당첨 내역을 출력한다. + +``` +3개 일치 (5,000원) - 1개 +4개 일치 (50,000원) - 0개 +5개 일치 (1,500,000원) - 0개 +5개 일치, 보너스 볼 일치 (30,000,000원) - 0개 +6개 일치 (2,000,000,000원) - 0개 +``` + +- 수익률은 소수점 둘째 자리에서 반올림한다. (ex. 100.0%, 51.5%, 1,000,000.0%) + +``` +총 수익률은 62.5%입니다. +``` + +- 예외 상황 시 에러 문구를 출력해야 한다. 단, 에러 문구는 "[ERROR]"로 시작해야 한다. + +``` +[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다. +``` + +# +### 구현 완료 여부 + +#### 입력 기능 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
완료 상태테스트
로또 구입 금액을 입력하면 구입 금액에 해당하는 만큼 로또를 발행해야 한다.
로또 1장의 가격은 1,000원이다. 1,000원으로 나누어 떨어지지 않는 경우 예외 처리한다.
당첨 번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다.
보너스 번호를 입력받는다.
로또 번호는 1-45사이 숫자이며 아닐 경우 예외 처리한다.
로또 번호가 중복되는 숫자일 경우 예외 처리한다.
+ +
+ + +#### 출력 기능 + + + + + + + + + + + + + + + + + + + + + + + + + + +
완료 상태테스트
발행한 로또 수량 및 번호를 출력한다.
로또 번호는 오름차순으로 정렬하여 보여준다.
당첨 내역을 출력한다.
수익률은 소수점 둘째 자리에서 반올림한다. (ex. 100.0%, 51.5%, 1,000,000.0%)
예외 상황 시 에러 문구를 출력해야 한다. 단, 에러 문구는 "[ERROR]"로 시작해야 한다
From 6e8fac7f7b9e77d8005a06fc657263e2f7dc2e5c Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 16:11:00 +0900 Subject: [PATCH 02/53] =?UTF-8?q?test=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/InputTest.js | 23 +++++++++++++++++++++++ src/constants/constants.js | 3 +++ src/veiw/input-veiw.js | 13 +++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 __tests__/InputTest.js create mode 100644 src/constants/constants.js create mode 100644 src/veiw/input-veiw.js diff --git a/__tests__/InputTest.js b/__tests__/InputTest.js new file mode 100644 index 0000000000..dc25eb7ea2 --- /dev/null +++ b/__tests__/InputTest.js @@ -0,0 +1,23 @@ +import { MissionUtils } from "@woowacourse/mission-utils"; +import InputVeiw from "../src/veiw/input-veiw"; + +const mockInput = (input) => { + MissionUtils.Console.readLineAsync = jest.fn(); + MissionUtils.Console.readLineAsync.mockResolvedValue(input); +}; + +describe("입력값 테스트", () => { + test("구입금액 입력 테스트", async () => { + //given + const input = 14000; + mockInput(input); + + //when + const inputValue = new InputVeiw() + const output = await inputValue.readPurchaseAmount(); + + //then + expect(output).toEqual(14); + }); +}); + \ No newline at end of file diff --git a/src/constants/constants.js b/src/constants/constants.js new file mode 100644 index 0000000000..f61cab5100 --- /dev/null +++ b/src/constants/constants.js @@ -0,0 +1,3 @@ +export const INPUT_MESSAGE = { + +}; \ No newline at end of file diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js new file mode 100644 index 0000000000..7d48ad1c9b --- /dev/null +++ b/src/veiw/input-veiw.js @@ -0,0 +1,13 @@ +import { Console } from "@woowacourse/mission-utils"; + +class InputVeiw{ + async readPurchaseAmount(){ + return null; + } + + async readWinningNumber(){ + return null; + } +} + +export default InputVeiw; \ No newline at end of file From 80054861696c22d823d443765de64605dea42241 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 16:13:34 +0900 Subject: [PATCH 03/53] =?UTF-8?q?feat=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/veiw/input-veiw.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index 7d48ad1c9b..246e9fdd85 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -2,7 +2,8 @@ import { Console } from "@woowacourse/mission-utils"; class InputVeiw{ async readPurchaseAmount(){ - return null; + const inputMoney = await Console.readLineAsync('구입금액을 입력해 주세요.\n'); + return inputMoney/1000; } async readWinningNumber(){ From 012e05001e50136525da6c242e6e4d4c5d46aa94 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 16:29:22 +0900 Subject: [PATCH 04/53] =?UTF-8?q?refactor=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EB=AC=B8=EA=B5=AC=20constants=20=ED=8C=8C=EC=9D=BC=EC=97=90=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 2 +- src/veiw/input-veiw.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index f61cab5100..970b884b44 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,3 +1,3 @@ export const INPUT_MESSAGE = { - + inputPurchaseAmount : '구입금액을 입력해 주세요.\n', }; \ No newline at end of file diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index 246e9fdd85..3e6b1d22f8 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -1,8 +1,9 @@ import { Console } from "@woowacourse/mission-utils"; +import { INPUT_MESSAGE } from "../constants/constants.js"; class InputVeiw{ async readPurchaseAmount(){ - const inputMoney = await Console.readLineAsync('구입금액을 입력해 주세요.\n'); + const inputMoney = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); return inputMoney/1000; } From 2796d78d6ec10a4fced5a4cc0b541cd6ed4423c4 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 16:40:29 +0900 Subject: [PATCH 05/53] =?UTF-8?q?test=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=EC=9D=B4=201000=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=82=98=EB=88=84=EC=96=B4=20=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EC=A7=80=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EA=B2=BD=EC=9A=B0?= =?UTF-8?q?=EC=9D=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/InputTest.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/__tests__/InputTest.js b/__tests__/InputTest.js index dc25eb7ea2..68298d86b5 100644 --- a/__tests__/InputTest.js +++ b/__tests__/InputTest.js @@ -19,5 +19,17 @@ describe("입력값 테스트", () => { //then expect(output).toEqual(14); }); + + test("구입금액이 1000으로 나누어 떨어지지 않을 경우 예외 처리", async () => { + //given + const input = 14500; + mockInput(input); + + //when + const inputValue = new InputVeiw() + + //then + await expect(inputValue.readPurchaseAmount()).rejects.toThrow("[ERROR]"); + }); }); \ No newline at end of file From e3ff45c8e5cce4d8efc9806ce3159f60ac7e159c Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 16:46:40 +0900 Subject: [PATCH 06/53] =?UTF-8?q?feat=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=EC=9D=B4=201000=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=82=98=EB=88=84=EC=96=B4=20=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EC=A7=80=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/veiw/input-veiw.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index 3e6b1d22f8..1e29c27b85 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -2,12 +2,15 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; class InputVeiw{ - async readPurchaseAmount(){ + async readPurchaseAmount() { const inputMoney = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); + if (inputMoney%1000 != 0) { + throw new Error("[ERROR] 구입금액은 1000으로 나누어 떨어지는 수 입니다."); + } return inputMoney/1000; } - async readWinningNumber(){ + async readWinningNumber() { return null; } } From 67e06d049b3beb751579b1ccb939c67682735698 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 17:53:40 +0900 Subject: [PATCH 07/53] =?UTF-8?q?refactor=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=EC=9D=B4=201000=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=82=98=EB=88=84=EC=96=B4=20=EB=96=A8=EC=96=B4?= =?UTF-8?q?=EC=A7=80=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 4 ++++ src/validation/input-validation.js | 7 +++++++ src/veiw/input-veiw.js | 7 +++---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/validation/input-validation.js diff --git a/src/constants/constants.js b/src/constants/constants.js index 970b884b44..e9c913363c 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,3 +1,7 @@ export const INPUT_MESSAGE = { inputPurchaseAmount : '구입금액을 입력해 주세요.\n', +}; + +export const ERROR_MESSAGE = { + perchaseError : '[ERROR] 구입금액은 1000으로 나누어 떨어지는 수 입니다.', }; \ No newline at end of file diff --git a/src/validation/input-validation.js b/src/validation/input-validation.js new file mode 100644 index 0000000000..82c542de46 --- /dev/null +++ b/src/validation/input-validation.js @@ -0,0 +1,7 @@ +import { ERROR_MESSAGE } from "../constants/constants.js"; + +export const inputPerChaseValidation = (perchase) => { + if (!Number.isInteger(perchase / 1000)) { + throw new Error(ERROR_MESSAGE.perchaseError); + } +}; \ No newline at end of file diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index 1e29c27b85..d4b2795bf8 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -1,13 +1,12 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; +import { inputPerChaseValidation } from "../validation/input-validation.js"; class InputVeiw{ async readPurchaseAmount() { const inputMoney = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - if (inputMoney%1000 != 0) { - throw new Error("[ERROR] 구입금액은 1000으로 나누어 떨어지는 수 입니다."); - } - return inputMoney/1000; + inputPerChaseValidation(inputMoney); + return inputMoney / 1000; } async readWinningNumber() { From 2c7934807e3cc75a235f2e0333103f50c36abbb8 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 17:58:04 +0900 Subject: [PATCH 08/53] =?UTF-8?q?docs=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index f5f183aa76..814ef182f6 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -94,11 +94,11 @@ 테스트 - + 로또 구입 금액을 입력하면 구입 금액에 해당하는 만큼 로또를 발행해야 한다. - + 로또 1장의 가격은 1,000원이다. 1,000원으로 나누어 떨어지지 않는 경우 예외 처리한다. From 91c83c0f740f285cab9e6b3c5cb0769ac406ee72 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 18:31:58 +0900 Subject: [PATCH 09/53] =?UTF-8?q?docs=20:=20=EA=B5=AC=EC=9E=85=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=EC=9D=B4=200=20=EC=9D=B4=ED=95=98=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/readme.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index 814ef182f6..435dce1eda 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -94,13 +94,17 @@ 테스트 - + 로또 구입 금액을 입력하면 구입 금액에 해당하는 만큼 로또를 발행해야 한다. 로또 1장의 가격은 1,000원이다. 1,000원으로 나누어 떨어지지 않는 경우 예외 처리한다. + + + 로또 구입 금액이 0 이하일 경우 예외 처리한다. + 당첨 번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다. From 4650eb28fa3fcc1b6ddb42626eb0aa9d706844df Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 18:36:26 +0900 Subject: [PATCH 10/53] =?UTF-8?q?test=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=20=EA=B8=88=EC=95=A1=EC=9D=B4=200=20?= =?UTF-8?q?=EC=9D=B4=ED=95=98=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- __tests__/InputTest.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/__tests__/InputTest.js b/__tests__/InputTest.js index 68298d86b5..804c252dba 100644 --- a/__tests__/InputTest.js +++ b/__tests__/InputTest.js @@ -7,29 +7,41 @@ const mockInput = (input) => { }; describe("입력값 테스트", () => { - test("구입금액 입력 테스트", async () => { + test("구입 금액 입력 테스트", async () => { //given const input = 14000; mockInput(input); //when - const inputValue = new InputVeiw() + const inputValue = new InputVeiw(); const output = await inputValue.readPurchaseAmount(); //then expect(output).toEqual(14); }); - test("구입금액이 1000으로 나누어 떨어지지 않을 경우 예외 처리", async () => { + test("구입 금액이 1000으로 나누어 떨어지지 않을 경우 예외 처리", async () => { //given const input = 14500; mockInput(input); //when - const inputValue = new InputVeiw() + const inputValue = new InputVeiw(); //then await expect(inputValue.readPurchaseAmount()).rejects.toThrow("[ERROR]"); }); -}); - \ No newline at end of file + + test.each([ + 0, -1000 + ])("구입 금액이 0 이하 일 경우 예외 처리", async (inputs) => { + //given + mockInput(inputs); + + //when + const inputValue = new InputVeiw(); + + //then + await expect(inputValue.readPurchaseAmount()).rejects.toThrow("[ERROR]"); + }); +}); \ No newline at end of file From afe2cb39dce3985e4501dfaabc010eb6bb47dc86 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 18:41:44 +0900 Subject: [PATCH 11/53] =?UTF-8?q?style=20:=20=EB=B3=80=EC=88=98=EB=AA=85?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20inputMoney=20->=20inputPrice,=20perchas?= =?UTF-8?q?e=20->=20price?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validation/input-validation.js | 4 ++-- src/veiw/input-veiw.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/validation/input-validation.js b/src/validation/input-validation.js index 82c542de46..8b38a5cad5 100644 --- a/src/validation/input-validation.js +++ b/src/validation/input-validation.js @@ -1,7 +1,7 @@ import { ERROR_MESSAGE } from "../constants/constants.js"; -export const inputPerChaseValidation = (perchase) => { - if (!Number.isInteger(perchase / 1000)) { +export const inputPerChaseValidation = (price) => { + if (!Number.isInteger(price / 1000)) { throw new Error(ERROR_MESSAGE.perchaseError); } }; \ No newline at end of file diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index d4b2795bf8..c3a99de9ee 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -4,9 +4,9 @@ import { inputPerChaseValidation } from "../validation/input-validation.js"; class InputVeiw{ async readPurchaseAmount() { - const inputMoney = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - inputPerChaseValidation(inputMoney); - return inputMoney / 1000; + const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); + inputPerChaseValidation(inputPrice); + return inputPrice / 1000; } async readWinningNumber() { From c5e12b59962c5ef0153741bb0fb009fa4c6d12d9 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 18:45:08 +0900 Subject: [PATCH 12/53] =?UTF-8?q?feat=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=20=EA=B8=88=EC=95=A1=EC=9D=B4=200=20?= =?UTF-8?q?=EC=9D=B4=ED=95=98=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/veiw/input-veiw.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index c3a99de9ee..e7a06381c3 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -5,6 +5,9 @@ import { inputPerChaseValidation } from "../validation/input-validation.js"; class InputVeiw{ async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); + if (inputPrice <= 0){ + throw new Error("[ERROR]"); + } inputPerChaseValidation(inputPrice); return inputPrice / 1000; } From 9fa1be873d43d3a1f4e150c1f829d977862821f7 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 19:22:06 +0900 Subject: [PATCH 13/53] =?UTF-8?q?refactor=20:=20(=EC=9E=85=EB=A0=A5)=20?= =?UTF-8?q?=EA=B5=AC=EC=9E=85=20=EA=B8=88=EC=95=A1=EC=9D=B4=200=20?= =?UTF-8?q?=EC=9D=B4=ED=95=98=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 5 +++-- src/validation/input-validation.js | 6 ++++++ src/veiw/input-veiw.js | 6 ++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index e9c913363c..ecb368a5a8 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,7 +1,8 @@ export const INPUT_MESSAGE = { - inputPurchaseAmount : '구입금액을 입력해 주세요.\n', + inputPurchaseAmount : "구입 금액을 입력해 주세요.\n", }; export const ERROR_MESSAGE = { - perchaseError : '[ERROR] 구입금액은 1000으로 나누어 떨어지는 수 입니다.', + perchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", + perchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", }; \ No newline at end of file diff --git a/src/validation/input-validation.js b/src/validation/input-validation.js index 8b38a5cad5..7f465d3eb0 100644 --- a/src/validation/input-validation.js +++ b/src/validation/input-validation.js @@ -4,4 +4,10 @@ export const inputPerChaseValidation = (price) => { if (!Number.isInteger(price / 1000)) { throw new Error(ERROR_MESSAGE.perchaseError); } +}; + +export const perchaseRangeValidation = (price) => { + if (price <= 0){ + throw new Error(ERROR_MESSAGE.perchaseRangeError); + } }; \ No newline at end of file diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index e7a06381c3..ab07d0a34e 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -1,13 +1,11 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; -import { inputPerChaseValidation } from "../validation/input-validation.js"; +import { inputPerChaseValidation, perchaseRangeValidation } from "../validation/input-validation.js"; class InputVeiw{ async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - if (inputPrice <= 0){ - throw new Error("[ERROR]"); - } + perchaseRangeValidation(inputPrice); inputPerChaseValidation(inputPrice); return inputPrice / 1000; } From b11a6df915da4b7e0db9272eb0df2993e090db09 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 19:27:32 +0900 Subject: [PATCH 14/53] =?UTF-8?q?docs=20:=20=EA=B5=AC=EC=9E=85=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=EC=9D=B4=200=20=EC=9D=B4=ED=95=98=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 435dce1eda..6687f90d9c 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -94,7 +94,7 @@ 테스트 - + 로또 구입 금액을 입력하면 구입 금액에 해당하는 만큼 로또를 발행해야 한다. @@ -102,7 +102,7 @@ 로또 1장의 가격은 1,000원이다. 1,000원으로 나누어 떨어지지 않는 경우 예외 처리한다. - + 로또 구입 금액이 0 이하일 경우 예외 처리한다. From 212de5d798b6b9678cdde7b4f59c4683083f30b1 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 20:21:14 +0900 Subject: [PATCH 15/53] =?UTF-8?q?rename=20:=20=ED=8C=8C=EC=9D=BC=EB=AA=85?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20Lotto.js=20->=20lotto.js=20,=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?model=ED=8F=B4=EB=8D=94=20=EC=95=88=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{Lotto.js => model/lotto.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Lotto.js => model/lotto.js} (100%) diff --git a/src/Lotto.js b/src/model/lotto.js similarity index 100% rename from src/Lotto.js rename to src/model/lotto.js From 9fa55443fd28cd39f9eeb42422d583bfbf230ec6 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 20:26:20 +0900 Subject: [PATCH 16/53] =?UTF-8?q?rename=20:=20InputTest.js=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20/=5F=5Fte?= =?UTF-8?q?sts=5F=5F=20->=20/=5F=5Ftests=5F=5F/veiw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/{ => veiw}/InputTest.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename __tests__/{ => veiw}/InputTest.js (100%) diff --git a/__tests__/InputTest.js b/__tests__/veiw/InputTest.js similarity index 100% rename from __tests__/InputTest.js rename to __tests__/veiw/InputTest.js From a71ae571a1fdf5384f3d9dbae5a5d33260dc52d8 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 20:26:59 +0900 Subject: [PATCH 17/53] =?UTF-8?q?rename=20:=20LottoTest.js=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD=20/=5F=5Fte?= =?UTF-8?q?sts=5F=5F=20->=20/=5F=5Ftests=5F=5F/model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/{ => model}/LottoTest.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename __tests__/{ => model}/LottoTest.js (100%) diff --git a/__tests__/LottoTest.js b/__tests__/model/LottoTest.js similarity index 100% rename from __tests__/LottoTest.js rename to __tests__/model/LottoTest.js From 95fcf5365f8c2e89bf3f9873180ff8c0404206a9 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 20:54:44 +0900 Subject: [PATCH 18/53] =?UTF-8?q?fix=20:=20LottoTest.js,=20InputTest.js=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20import=20=EA=B2=BD=EB=A1=9C=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 --- __tests__/model/LottoTest.js | 2 +- __tests__/veiw/InputTest.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/model/LottoTest.js b/__tests__/model/LottoTest.js index 97bd457659..fa8f27a797 100644 --- a/__tests__/model/LottoTest.js +++ b/__tests__/model/LottoTest.js @@ -1,4 +1,4 @@ -import Lotto from "../src/Lotto.js"; +import Lotto from "../../src/model/Lotto"; describe("로또 클래스 테스트", () => { test("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.", () => { diff --git a/__tests__/veiw/InputTest.js b/__tests__/veiw/InputTest.js index 804c252dba..30041f2517 100644 --- a/__tests__/veiw/InputTest.js +++ b/__tests__/veiw/InputTest.js @@ -1,5 +1,5 @@ import { MissionUtils } from "@woowacourse/mission-utils"; -import InputVeiw from "../src/veiw/input-veiw"; +import InputVeiw from "../../src/veiw/input-veiw"; const mockInput = (input) => { MissionUtils.Console.readLineAsync = jest.fn(); From 6759b098101774a159255dd5f28a0c71b04782a3 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Sun, 5 Nov 2023 20:57:42 +0900 Subject: [PATCH 19/53] =?UTF-8?q?fix=20:=20lotto.js=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?LottoTest.js=20import=20=EB=B6=80=EB=B6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/model/LottoTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/model/LottoTest.js b/__tests__/model/LottoTest.js index fa8f27a797..9d01bac718 100644 --- a/__tests__/model/LottoTest.js +++ b/__tests__/model/LottoTest.js @@ -1,4 +1,4 @@ -import Lotto from "../../src/model/Lotto"; +import Lotto from "../../src/model/lotto"; describe("로또 클래스 테스트", () => { test("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.", () => { From c0bd06573a13f18dd7ebe3fa26617116e375a3f3 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Tue, 7 Nov 2023 18:22:42 +0900 Subject: [PATCH 20/53] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EA=B0=AF=EC=88=98=20=EA=B2=80=EC=82=AC=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20lotto-validation=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=EB=A7=8C=EB=93=A4=EC=96=B4=EC=84=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 1 + src/model/lotto.js | 6 +++--- src/validation/lotto-validation.js | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/validation/lotto-validation.js diff --git a/src/constants/constants.js b/src/constants/constants.js index ecb368a5a8..6db04cedeb 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -5,4 +5,5 @@ export const INPUT_MESSAGE = { export const ERROR_MESSAGE = { perchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", perchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", + lottoLengthError : "[ERROR] 로또 번호는 6개여야 합니다.", }; \ No newline at end of file diff --git a/src/model/lotto.js b/src/model/lotto.js index cb0b1527e9..d9fea5bc56 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -1,3 +1,5 @@ +import { lottoLengthValidation } from "../validation/lotto-validation.js"; + class Lotto { #numbers; @@ -7,9 +9,7 @@ class Lotto { } #validate(numbers) { - if (numbers.length !== 6) { - throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); - } + lottoLengthValidation(numbers); } // TODO: 추가 기능 구현 diff --git a/src/validation/lotto-validation.js b/src/validation/lotto-validation.js new file mode 100644 index 0000000000..165b91a240 --- /dev/null +++ b/src/validation/lotto-validation.js @@ -0,0 +1,7 @@ +import { ERROR_MESSAGE } from "../constants/constants.js"; + +export const lottoLengthValidation = (numbers) => { + if (numbers.length !== 6) { + throw new Error(ERROR_MESSAGE.lottoLengthError); + } +}; \ No newline at end of file From b22de468fb0b5ec9ac0931608c7e9e3a851b4412 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Tue, 7 Nov 2023 18:40:08 +0900 Subject: [PATCH 21/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=A4=91=EB=B3=B5=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 1 + src/model/lotto.js | 3 ++- src/validation/lotto-validation.js | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 6db04cedeb..73babb254c 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -6,4 +6,5 @@ export const ERROR_MESSAGE = { perchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", perchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", lottoLengthError : "[ERROR] 로또 번호는 6개여야 합니다.", + lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", }; \ No newline at end of file diff --git a/src/model/lotto.js b/src/model/lotto.js index d9fea5bc56..bdf82c6bb3 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -1,4 +1,4 @@ -import { lottoLengthValidation } from "../validation/lotto-validation.js"; +import { lottoLengthValidation, lottoDuplicatedValidation } from "../validation/lotto-validation.js"; class Lotto { #numbers; @@ -10,6 +10,7 @@ class Lotto { #validate(numbers) { lottoLengthValidation(numbers); + lottoDuplicatedValidation(numbers); } // TODO: 추가 기능 구현 diff --git a/src/validation/lotto-validation.js b/src/validation/lotto-validation.js index 165b91a240..eb850881f1 100644 --- a/src/validation/lotto-validation.js +++ b/src/validation/lotto-validation.js @@ -4,4 +4,13 @@ export const lottoLengthValidation = (numbers) => { if (numbers.length !== 6) { throw new Error(ERROR_MESSAGE.lottoLengthError); } -}; \ No newline at end of file +}; + +export const lottoDuplicatedValidation = (numbers) => { + const isDup = numbers.some(function(x) { + return numbers.indexOf(x) !== numbers.lastIndexOf(x); + }); + if (isDup) { + throw new Error(ERROR_MESSAGE.lottoDuplicatedError); + } +} \ No newline at end of file From fa9301e90f8d7ade63c175f9a2b9601bd51d0aed Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 09:08:31 +0900 Subject: [PATCH 22/53] =?UTF-8?q?test=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=201-45=EB=B2=94=EC=9C=84=EB=A5=BC=20?= =?UTF-8?q?=EC=B4=88=EA=B3=BC=ED=95=98=EB=A9=B4=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- __tests__/model/LottoTest.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/__tests__/model/LottoTest.js b/__tests__/model/LottoTest.js index 9d01bac718..83c93462df 100644 --- a/__tests__/model/LottoTest.js +++ b/__tests__/model/LottoTest.js @@ -7,12 +7,15 @@ describe("로또 클래스 테스트", () => { }).toThrow("[ERROR]"); }); - // TODO: 이 테스트가 통과할 수 있게 구현 코드 작성 test("로또 번호에 중복된 숫자가 있으면 예외가 발생한다.", () => { expect(() => { new Lotto([1, 2, 3, 4, 5, 5]); }).toThrow("[ERROR]"); }); - // 아래에 추가 테스트 작성 가능 + test("로또 번호 1~45 범위를 초과하면 예외가 발생한다.", () => { + expect(() => { + new Lotto([1, 2, 3, 4, 5, 46]); + }).toThrow("[ERROR]"); + }); }); From b7fc29b0783de18d269b5ba2a476c457cb503ce2 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 09:29:53 +0900 Subject: [PATCH 23/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=201-45=20=EB=B2=94=EC=9C=84=EB=A5=BC=20?= =?UTF-8?q?=EC=B4=88=EA=B3=BC=ED=95=A0=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 1 + src/model/lotto.js | 3 ++- src/validation/lotto-validation.js | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 73babb254c..61e2b7888d 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -7,4 +7,5 @@ export const ERROR_MESSAGE = { perchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", lottoLengthError : "[ERROR] 로또 번호는 6개여야 합니다.", lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", + lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다." }; \ No newline at end of file diff --git a/src/model/lotto.js b/src/model/lotto.js index bdf82c6bb3..4075183c18 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -1,4 +1,4 @@ -import { lottoLengthValidation, lottoDuplicatedValidation } from "../validation/lotto-validation.js"; +import { lottoLengthValidation, lottoDuplicatedValidation, lottoRangeValidation } from "../validation/lotto-validation.js"; class Lotto { #numbers; @@ -11,6 +11,7 @@ class Lotto { #validate(numbers) { lottoLengthValidation(numbers); lottoDuplicatedValidation(numbers); + lottoRangeValidation(numbers); } // TODO: 추가 기능 구현 diff --git a/src/validation/lotto-validation.js b/src/validation/lotto-validation.js index eb850881f1..2b78ddd7bc 100644 --- a/src/validation/lotto-validation.js +++ b/src/validation/lotto-validation.js @@ -13,4 +13,13 @@ export const lottoDuplicatedValidation = (numbers) => { if (isDup) { throw new Error(ERROR_MESSAGE.lottoDuplicatedError); } -} \ No newline at end of file +}; + +export const lottoRangeValidation = (numbers) => { + const isOutOfRange = numbers.some(function(number) { + return number < 1 || number > 45; + }); + if (isOutOfRange) { + throw new Error(ERROR_MESSAGE.lottoRangeError); + } +}; \ No newline at end of file From a953c67cf9b9c5e040a2378d6115ac64b4666409 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 10:30:54 +0900 Subject: [PATCH 24/53] =?UTF-8?q?refactor=20:=20lotto=EC=9D=98=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EB=AC=B6?= =?UTF-8?q?=EC=96=B4=EC=84=9C=20export=20=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/lotto.js | 8 +++--- src/validation/lotto-validation.js | 40 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/model/lotto.js b/src/model/lotto.js index 4075183c18..1afc1fb5e8 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -1,4 +1,4 @@ -import { lottoLengthValidation, lottoDuplicatedValidation, lottoRangeValidation } from "../validation/lotto-validation.js"; +import LottoValidator from "../validation/lotto-validation.js"; class Lotto { #numbers; @@ -9,9 +9,9 @@ class Lotto { } #validate(numbers) { - lottoLengthValidation(numbers); - lottoDuplicatedValidation(numbers); - lottoRangeValidation(numbers); + LottoValidator.lottoLengthValidation(numbers); + LottoValidator.lottoDuplicatedValidation(numbers); + LottoValidator.lottoRangeValidation(numbers); } // TODO: 추가 기능 구현 diff --git a/src/validation/lotto-validation.js b/src/validation/lotto-validation.js index 2b78ddd7bc..658287a429 100644 --- a/src/validation/lotto-validation.js +++ b/src/validation/lotto-validation.js @@ -1,25 +1,29 @@ import { ERROR_MESSAGE } from "../constants/constants.js"; -export const lottoLengthValidation = (numbers) => { - if (numbers.length !== 6) { - throw new Error(ERROR_MESSAGE.lottoLengthError); +class LottoValidator { + static lottoLengthValidation(numbers) { + if (numbers.length !== 6) { + throw new Error(ERROR_MESSAGE.lottoLengthError); + } } -}; -export const lottoDuplicatedValidation = (numbers) => { - const isDup = numbers.some(function(x) { - return numbers.indexOf(x) !== numbers.lastIndexOf(x); - }); - if (isDup) { - throw new Error(ERROR_MESSAGE.lottoDuplicatedError); + static lottoDuplicatedValidation(numbers) { + const isDup = numbers.some(function(x) { + return numbers.indexOf(x) !== numbers.lastIndexOf(x); + }); + if (isDup) { + throw new Error(ERROR_MESSAGE.lottoDuplicatedError); + } } -}; -export const lottoRangeValidation = (numbers) => { - const isOutOfRange = numbers.some(function(number) { - return number < 1 || number > 45; - }); - if (isOutOfRange) { - throw new Error(ERROR_MESSAGE.lottoRangeError); + static lottoRangeValidation(numbers) { + const isOutOfRange = numbers.some(function(number) { + return number < 1 || number > 45; + }); + if (isOutOfRange) { + throw new Error(ERROR_MESSAGE.lottoRangeError); + } } -}; \ No newline at end of file +} + +export default LottoValidator; From 9fcc56ac81bab58b301fc7f018ecff2e95d86473 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 10:33:24 +0900 Subject: [PATCH 25/53] =?UTF-8?q?refactor=20:=20input=EA=B0=92=EC=9D=98=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=93=A4=EC=9D=84=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20?= =?UTF-8?q?=EB=AC=B6=EC=96=B4=EC=84=9C=20export=20=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validation/input-validation.js | 20 ++++++++++++-------- src/veiw/input-veiw.js | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/validation/input-validation.js b/src/validation/input-validation.js index 7f465d3eb0..eb0d25cb1e 100644 --- a/src/validation/input-validation.js +++ b/src/validation/input-validation.js @@ -1,13 +1,17 @@ import { ERROR_MESSAGE } from "../constants/constants.js"; -export const inputPerChaseValidation = (price) => { - if (!Number.isInteger(price / 1000)) { - throw new Error(ERROR_MESSAGE.perchaseError); +class InputValidator { + static inputPurchaseValidation(price) { + if (!Number.isInteger(price / 1000)) { + throw new Error(ERROR_MESSAGE.purchaseError); + } } -}; -export const perchaseRangeValidation = (price) => { - if (price <= 0){ - throw new Error(ERROR_MESSAGE.perchaseRangeError); + static purchaseRangeValidation(price) { + if (price <= 0) { + throw new Error(ERROR_MESSAGE.purchaseRangeError); + } } -}; \ No newline at end of file +} + +export default InputValidator; diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index ab07d0a34e..4f4f784c7b 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -1,12 +1,12 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; -import { inputPerChaseValidation, perchaseRangeValidation } from "../validation/input-validation.js"; +import InputValidator from "../validation/input-validation.js"; class InputVeiw{ async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - perchaseRangeValidation(inputPrice); - inputPerChaseValidation(inputPrice); + InputValidator.perchaseRangeValidation(inputPrice); + InputValidator.inputPerChaseValidation(inputPrice); return inputPrice / 1000; } From 6d2bad03c5a4fa93a70b1299e09cf2b539a1c697 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 10:36:49 +0900 Subject: [PATCH 26/53] =?UTF-8?q?rename=20:=20validation=ED=8F=B4=EB=8D=94?= =?UTF-8?q?=EB=AA=85=EA=B3=BC=20=ED=8C=8C=EC=9D=BC=EB=AA=85=EC=9D=84=20val?= =?UTF-8?q?idator=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/lotto.js | 2 +- .../input-validation.js => validator/input-validator.js} | 0 .../lotto-validation.js => validator/lotto-validator.js} | 0 src/veiw/input-veiw.js | 2 +- 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{validation/input-validation.js => validator/input-validator.js} (100%) rename src/{validation/lotto-validation.js => validator/lotto-validator.js} (100%) diff --git a/src/model/lotto.js b/src/model/lotto.js index 1afc1fb5e8..c3942bdb74 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -1,4 +1,4 @@ -import LottoValidator from "../validation/lotto-validation.js"; +import LottoValidator from "../validator/lotto-validator.js"; class Lotto { #numbers; diff --git a/src/validation/input-validation.js b/src/validator/input-validator.js similarity index 100% rename from src/validation/input-validation.js rename to src/validator/input-validator.js diff --git a/src/validation/lotto-validation.js b/src/validator/lotto-validator.js similarity index 100% rename from src/validation/lotto-validation.js rename to src/validator/lotto-validator.js diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index 4f4f784c7b..e221b4d1c9 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -1,6 +1,6 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; -import InputValidator from "../validation/input-validation.js"; +import InputValidator from "../validator/input-validator.js"; class InputVeiw{ async readPurchaseAmount() { From e54e23d765171f282e3d15682a9913d9af8a56c6 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 10:42:55 +0900 Subject: [PATCH 27/53] =?UTF-8?q?fix=20:=20InputValidator=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=A9=B4?= =?UTF-8?q?=EC=84=9C=20=ED=95=A8=EC=88=98=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 4 ++-- src/veiw/input-veiw.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 61e2b7888d..35b3dc43c0 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -3,8 +3,8 @@ export const INPUT_MESSAGE = { }; export const ERROR_MESSAGE = { - perchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", - perchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", + purchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", + purchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", lottoLengthError : "[ERROR] 로또 번호는 6개여야 합니다.", lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다." diff --git a/src/veiw/input-veiw.js b/src/veiw/input-veiw.js index e221b4d1c9..b8aab15768 100644 --- a/src/veiw/input-veiw.js +++ b/src/veiw/input-veiw.js @@ -5,8 +5,8 @@ import InputValidator from "../validator/input-validator.js"; class InputVeiw{ async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - InputValidator.perchaseRangeValidation(inputPrice); - InputValidator.inputPerChaseValidation(inputPrice); + InputValidator.purchaseRangeValidation(inputPrice); + InputValidator.inputPurchaseValidation(inputPrice); return inputPrice / 1000; } From 4ea4ef385cf1c7c641a4e53b1b48749a7d9190e0 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:13:14 +0900 Subject: [PATCH 28/53] =?UTF-8?q?style=20:=20=EA=B0=9D=EC=B2=B4=EB=AA=85,?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=EB=AA=85=20=EC=98=A4=ED=83=80=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 --- __tests__/{veiw => view}/InputTest.js | 8 ++++---- src/{veiw/input-veiw.js => view/input-view.js} | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename __tests__/{veiw => view}/InputTest.js (85%) rename src/{veiw/input-veiw.js => view/input-view.js} (92%) diff --git a/__tests__/veiw/InputTest.js b/__tests__/view/InputTest.js similarity index 85% rename from __tests__/veiw/InputTest.js rename to __tests__/view/InputTest.js index 30041f2517..d04a8b87ae 100644 --- a/__tests__/veiw/InputTest.js +++ b/__tests__/view/InputTest.js @@ -1,5 +1,5 @@ import { MissionUtils } from "@woowacourse/mission-utils"; -import InputVeiw from "../../src/veiw/input-veiw"; +import InputView from "../../src/view/input-view"; const mockInput = (input) => { MissionUtils.Console.readLineAsync = jest.fn(); @@ -13,7 +13,7 @@ describe("입력값 테스트", () => { mockInput(input); //when - const inputValue = new InputVeiw(); + const inputValue = new InputView(); const output = await inputValue.readPurchaseAmount(); //then @@ -26,7 +26,7 @@ describe("입력값 테스트", () => { mockInput(input); //when - const inputValue = new InputVeiw(); + const inputValue = new InputView(); //then await expect(inputValue.readPurchaseAmount()).rejects.toThrow("[ERROR]"); @@ -39,7 +39,7 @@ describe("입력값 테스트", () => { mockInput(inputs); //when - const inputValue = new InputVeiw(); + const inputValue = new InputView(); //then await expect(inputValue.readPurchaseAmount()).rejects.toThrow("[ERROR]"); diff --git a/src/veiw/input-veiw.js b/src/view/input-view.js similarity index 92% rename from src/veiw/input-veiw.js rename to src/view/input-view.js index b8aab15768..ed27a668ef 100644 --- a/src/veiw/input-veiw.js +++ b/src/view/input-view.js @@ -2,7 +2,7 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; import InputValidator from "../validator/input-validator.js"; -class InputVeiw{ +class InputView{ async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); InputValidator.purchaseRangeValidation(inputPrice); @@ -15,4 +15,4 @@ class InputVeiw{ } } -export default InputVeiw; \ No newline at end of file +export default InputView; \ No newline at end of file From 337c99d9c095df65eccca8be7042449db4760133 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:22:10 +0900 Subject: [PATCH 29/53] =?UTF-8?q?style=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=EC=97=90=20=EB=94=B0=EB=9D=BC=20Lotto.js=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EB=AA=85=20=EB=8B=A4=EC=8B=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/model/LottoTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/model/LottoTest.js b/__tests__/model/LottoTest.js index 83c93462df..4ed96a59c3 100644 --- a/__tests__/model/LottoTest.js +++ b/__tests__/model/LottoTest.js @@ -1,4 +1,4 @@ -import Lotto from "../../src/model/lotto"; +import Lotto from "../../src/model/Lotto"; describe("로또 클래스 테스트", () => { test("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.", () => { From d5fb05ef9c91e7f1f2bc4be0d8cf16f3761f6884 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:25:58 +0900 Subject: [PATCH 30/53] =?UTF-8?q?test=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=8A=94=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/view/InputTest.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/__tests__/view/InputTest.js b/__tests__/view/InputTest.js index d04a8b87ae..b9b1bea79d 100644 --- a/__tests__/view/InputTest.js +++ b/__tests__/view/InputTest.js @@ -7,19 +7,6 @@ const mockInput = (input) => { }; describe("입력값 테스트", () => { - test("구입 금액 입력 테스트", async () => { - //given - const input = 14000; - mockInput(input); - - //when - const inputValue = new InputView(); - const output = await inputValue.readPurchaseAmount(); - - //then - expect(output).toEqual(14); - }); - test("구입 금액이 1000으로 나누어 떨어지지 않을 경우 예외 처리", async () => { //given const input = 14500; From d2edae77a32e341e1d3869057835d49e8e5df207 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:27:17 +0900 Subject: [PATCH 31/53] =?UTF-8?q?style=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=A3=BC=EC=84=9D=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=EA=B0=92=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A1=9C=20=ED=85=8D?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/view/InputTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/view/InputTest.js b/__tests__/view/InputTest.js index b9b1bea79d..d2dd5666d2 100644 --- a/__tests__/view/InputTest.js +++ b/__tests__/view/InputTest.js @@ -6,7 +6,7 @@ const mockInput = (input) => { MissionUtils.Console.readLineAsync.mockResolvedValue(input); }; -describe("입력값 테스트", () => { +describe("입력값 예외처리 테스트", () => { test("구입 금액이 1000으로 나누어 떨어지지 않을 경우 예외 처리", async () => { //given const input = 14500; From 1fa00b2bed0270f854f64153ddd84c2eaa4534b3 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:35:39 +0900 Subject: [PATCH 32/53] =?UTF-8?q?docs=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=9E=90=EC=97=B0=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=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 --- docs/readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/readme.md b/docs/readme.md index 6687f90d9c..ce108f7700 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -105,6 +105,10 @@ 로또 구입 금액이 0 이하일 경우 예외 처리한다. + + + 로또 번호가 자연수가 아닐 경우 예외 처리한다. + 당첨 번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다. From 2c716164ad2f5821a6c37ff40eb3d614ba015750 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:37:02 +0900 Subject: [PATCH 33/53] =?UTF-8?q?test=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=9E=90=EC=97=B0=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=20=EA=B2=BD=EC=9A=B0=EC=9D=98=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/model/LottoTest.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/__tests__/model/LottoTest.js b/__tests__/model/LottoTest.js index 4ed96a59c3..b789c80486 100644 --- a/__tests__/model/LottoTest.js +++ b/__tests__/model/LottoTest.js @@ -18,4 +18,9 @@ describe("로또 클래스 테스트", () => { new Lotto([1, 2, 3, 4, 5, 46]); }).toThrow("[ERROR]"); }); + test("로또 번호가 자연수가 아니면 예외가 발생한다.", () => { + expect(() => { + new Lotto([1, 2, 3, 4, 5, 6.5]); + }).toThrow("[ERROR]"); + }); }); From c9623c5a8b74706efb03d1eeb7572f0957d4fce6 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:48:28 +0900 Subject: [PATCH 34/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=9E=90=EC=97=B0=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 3 ++- src/model/lotto.js | 1 + src/validator/lotto-validator.js | 13 +++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 35b3dc43c0..45ffe3942b 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -7,5 +7,6 @@ export const ERROR_MESSAGE = { purchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", lottoLengthError : "[ERROR] 로또 번호는 6개여야 합니다.", lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", - lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다." + lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다.", + lottoTypeError : "[ERROR] 로또 번호는 자연수입니다.", }; \ No newline at end of file diff --git a/src/model/lotto.js b/src/model/lotto.js index c3942bdb74..6a44aee601 100644 --- a/src/model/lotto.js +++ b/src/model/lotto.js @@ -12,6 +12,7 @@ class Lotto { LottoValidator.lottoLengthValidation(numbers); LottoValidator.lottoDuplicatedValidation(numbers); LottoValidator.lottoRangeValidation(numbers); + LottoValidator.lottoTypeValidation(numbers); } // TODO: 추가 기능 구현 diff --git a/src/validator/lotto-validator.js b/src/validator/lotto-validator.js index 658287a429..13462417c8 100644 --- a/src/validator/lotto-validator.js +++ b/src/validator/lotto-validator.js @@ -8,10 +8,10 @@ class LottoValidator { } static lottoDuplicatedValidation(numbers) { - const isDup = numbers.some(function(x) { + const isDuplicated = numbers.some(function(x) { return numbers.indexOf(x) !== numbers.lastIndexOf(x); }); - if (isDup) { + if (isDuplicated) { throw new Error(ERROR_MESSAGE.lottoDuplicatedError); } } @@ -24,6 +24,15 @@ class LottoValidator { throw new Error(ERROR_MESSAGE.lottoRangeError); } } + + static lottoTypeValidation(numbers) { + const isTypeValid = numbers.every((element) => { + return Number.isInteger(element); + }); + if (!isTypeValid) { + throw new Error(ERROR_MESSAGE.lottoTypeError); + } + } } export default LottoValidator; From cca7f881de85779b8b0ac75e0d8c0021e11ccd64 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:48:57 +0900 Subject: [PATCH 35/53] =?UTF-8?q?docs=20:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EC=9E=90=EC=97=B0=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=99=84=EB=A3=8C?= 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 ce108f7700..3d34383fd2 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -106,7 +106,7 @@ 로또 구입 금액이 0 이하일 경우 예외 처리한다. - + 로또 번호가 자연수가 아닐 경우 예외 처리한다. From a1e2721d5b3e55623f42d5dcea06607fbfd46076 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 14:53:19 +0900 Subject: [PATCH 36/53] =?UTF-8?q?rename=20:=20model=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EB=AA=85=20domain=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/{model => domain}/LottoTest.js | 0 src/{model/lotto.js => domain/Lotto.js} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename __tests__/{model => domain}/LottoTest.js (100%) rename src/{model/lotto.js => domain/Lotto.js} (100%) diff --git a/__tests__/model/LottoTest.js b/__tests__/domain/LottoTest.js similarity index 100% rename from __tests__/model/LottoTest.js rename to __tests__/domain/LottoTest.js diff --git a/src/model/lotto.js b/src/domain/Lotto.js similarity index 100% rename from src/model/lotto.js rename to src/domain/Lotto.js From a69cd68449fc9fa2b4aa6003d3a9d781f030b9b9 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 16:02:17 +0900 Subject: [PATCH 37/53] =?UTF-8?q?feat=20:=20LottoController=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/App.js | 12 +++++++++++- src/controller/lotto-controller.js | 15 +++++++++++++++ src/view/input-view.js | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/controller/lotto-controller.js diff --git a/src/App.js b/src/App.js index c38b30d5b2..76de5dfee7 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,15 @@ +import LottoController from "./controller/lotto-controller.js"; + class App { - async play() {} + #lottoController; + + constructor() { + this.#lottoController = new LottoController(); + } + + async play() { + await this.#lottoController.play(); + } } export default App; diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js new file mode 100644 index 0000000000..a54375317a --- /dev/null +++ b/src/controller/lotto-controller.js @@ -0,0 +1,15 @@ +import InputView from "../view/input-view.js"; + +class LottoController { + #inputView; + + constructor() { + this.#inputView = new InputView(); + } + + async play() { + let count = await this.#inputView.readPurchaseAmount(); + } +} + +export default LottoController; \ No newline at end of file diff --git a/src/view/input-view.js b/src/view/input-view.js index ed27a668ef..cca1a2692d 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -2,7 +2,7 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; import InputValidator from "../validator/input-validator.js"; -class InputView{ +class InputView { async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); InputValidator.purchaseRangeValidation(inputPrice); From 71fd7589516ef5bce4672a8f9b57ba10b57a3ac9 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 16:23:47 +0900 Subject: [PATCH 38/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=9E=9C=EB=8D=A4=20=EC=83=9D=EC=84=B1=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/lotto-number-generator.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/util/lotto-number-generator.js diff --git a/src/util/lotto-number-generator.js b/src/util/lotto-number-generator.js new file mode 100644 index 0000000000..f6aa08980d --- /dev/null +++ b/src/util/lotto-number-generator.js @@ -0,0 +1,12 @@ +import { Random } from "@woowacourse/mission-utils"; + +const randomNumberGenerator = () => { + return Random.pickUniqueNumbersInRange(1, 45, 6); +}; + +const lottoNumberGenerator = () => { + const lottoNumbers = randomNumberGenerator(); + return lottoNumbers.sort((a, b) => a - b); +}; + +export default lottoNumberGenerator; \ No newline at end of file From 24a699dec341fd2f3e443f965717d9583a6102a2 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 16:35:11 +0900 Subject: [PATCH 39/53] =?UTF-8?q?feat=20:=20Lotto=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EB=98=90=20=EB=B2=88=ED=98=B8=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20getNumbers=ED=95=A8?= =?UTF-8?q?=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 --- __tests__/domain/LottoTest.js | 2 +- src/domain/Lotto.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/__tests__/domain/LottoTest.js b/__tests__/domain/LottoTest.js index b789c80486..e17d672c6e 100644 --- a/__tests__/domain/LottoTest.js +++ b/__tests__/domain/LottoTest.js @@ -1,4 +1,4 @@ -import Lotto from "../../src/model/Lotto"; +import Lotto from "../../src/domain/Lotto"; describe("로또 클래스 테스트", () => { test("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.", () => { diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 6a44aee601..97ec8c8f8d 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -15,7 +15,9 @@ class Lotto { LottoValidator.lottoTypeValidation(numbers); } - // TODO: 추가 기능 구현 + getNumbers() { + return this.#numbers; + } } export default Lotto; From 3afbc0d977a5ac7f0b739e98d9580551d10bb92c Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 17:57:32 +0900 Subject: [PATCH 40/53] =?UTF-8?q?feat=20:=20MyLotto=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 8 ++++++++ src/domain/MyLotto.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/domain/MyLotto.js diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index a54375317a..a58418e54b 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -1,4 +1,6 @@ +import MyLotto from "../domain/MyLotto.js"; import InputView from "../view/input-view.js"; +import { Console } from "@woowacourse/mission-utils"; class LottoController { #inputView; @@ -9,6 +11,12 @@ class LottoController { async play() { let count = await this.#inputView.readPurchaseAmount(); + let lottos = new MyLotto(count); + Console.print(`\n${count}개를 구매했습니다.`); + for (let element of lottos.getMyLottos()){ + Console.print(element.getNumbers()); + } + } } diff --git a/src/domain/MyLotto.js b/src/domain/MyLotto.js new file mode 100644 index 0000000000..ce34af240e --- /dev/null +++ b/src/domain/MyLotto.js @@ -0,0 +1,24 @@ +import Lotto from "./Lotto.js"; +import lottoNumberGenerator from "../util/lotto-number-generator.js"; + +class MyLotto { + #lottos; + + constructor(purchaseAmount) { + this.#lottos = this.#generate(purchaseAmount); + } + + #generate(purchaseAmount) { + let generator = []; + for (let i = 0; i < purchaseAmount; i++) { + generator.push(new Lotto(lottoNumberGenerator())); + } + return generator; + } + + getMyLottos() { + return this.#lottos; + } +} + +export default MyLotto; \ No newline at end of file From 3c359c1dae7c88c19aba2d7c49269ef69e20b975 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 18:53:21 +0900 Subject: [PATCH 41/53] =?UTF-8?q?refactor=20:=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 4 ++++ src/controller/lotto-controller.js | 17 ++++++++--------- src/view/output-view.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/view/output-view.js diff --git a/src/constants/constants.js b/src/constants/constants.js index 45ffe3942b..e934e84517 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -2,6 +2,10 @@ export const INPUT_MESSAGE = { inputPurchaseAmount : "구입 금액을 입력해 주세요.\n", }; +export const OUTPUT_MESSAGE = { + printPurchaseNumber : (count) => `\n${count}개 구매했습니다.`, +}; + export const ERROR_MESSAGE = { purchaseError : "[ERROR] 구입 금액은 1000으로 나누어 떨어지는 수 입니다.", purchaseRangeError : "[ERROR] 구입 금액 범위는 양수인 정수입니다.", diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index a58418e54b..5c7625ba9a 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -1,22 +1,21 @@ import MyLotto from "../domain/MyLotto.js"; import InputView from "../view/input-view.js"; -import { Console } from "@woowacourse/mission-utils"; +import OutputView from "../view/output-view.js"; + class LottoController { - #inputView; + #inputView + #outputView constructor() { this.#inputView = new InputView(); + this.#outputView = new OutputView(); } async play() { - let count = await this.#inputView.readPurchaseAmount(); - let lottos = new MyLotto(count); - Console.print(`\n${count}개를 구매했습니다.`); - for (let element of lottos.getMyLottos()){ - Console.print(element.getNumbers()); - } - + let perchaseNumber = await this.#inputView.readPurchaseAmount(); + let myLotto = new MyLotto(perchaseNumber); + this.#outputView.printMyLotto(perchaseNumber, myLotto); } } diff --git a/src/view/output-view.js b/src/view/output-view.js new file mode 100644 index 0000000000..db01a4267d --- /dev/null +++ b/src/view/output-view.js @@ -0,0 +1,14 @@ +import { OUTPUT_MESSAGE } from "../constants/constants.js"; +import { Console } from "@woowacourse/mission-utils"; + +class OutputView { + printMyLotto(perchaseNumber, myLotto) { + Console.print(OUTPUT_MESSAGE.printPurchaseNumber(perchaseNumber)); + + for (let element of myLotto.getMyLottos()) { + Console.print(element.getNumbers()); + } + } +}; + +export default OutputView; \ No newline at end of file From d75fe0ba6a192ade149a7ac960ffc4a2c6e32cb2 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 19:04:06 +0900 Subject: [PATCH 42/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=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=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 1 + src/view/input-view.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index e934e84517..9328b56655 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,5 +1,6 @@ export const INPUT_MESSAGE = { inputPurchaseAmount : "구입 금액을 입력해 주세요.\n", + inputWinningNumbers : "당첨 번호를 입력해 주세요.\n", }; export const OUTPUT_MESSAGE = { diff --git a/src/view/input-view.js b/src/view/input-view.js index cca1a2692d..90fe0fdc8a 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -1,6 +1,7 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; import InputValidator from "../validator/input-validator.js"; +import LottoValidator from "../validator/lotto-validator.js"; class InputView { async readPurchaseAmount() { @@ -11,8 +12,15 @@ class InputView { } async readWinningNumber() { - return null; + const winningNumbers = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); + LottoValidator.lottoLengthValidation(winningNumbers); + LottoValidator.lottoDuplicatedValidation(winningNumbers); + LottoValidator.lottoRangeValidation(winningNumbers); + LottoValidator.lottoTypeValidation(winningNumbers); + return winningNumbers; } + + async readBonusNumber() {} } export default InputView; \ No newline at end of file From 7d113441da9bb499dbeac1a1428bb7d9247a5fac Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 19:18:01 +0900 Subject: [PATCH 43/53] =?UTF-8?q?feat=20:=20=EB=B3=B4=EB=84=88=EC=8A=A4=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=20=EA=B8=B0=EB=8A=A5=EA=B3=BC=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=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 4 +++- src/validator/lotto-bonus-validator.js | 25 +++++++++++++++++++++++++ src/view/input-view.js | 9 ++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/validator/lotto-bonus-validator.js diff --git a/src/constants/constants.js b/src/constants/constants.js index 9328b56655..597fe335c4 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -1,6 +1,7 @@ export const INPUT_MESSAGE = { inputPurchaseAmount : "구입 금액을 입력해 주세요.\n", - inputWinningNumbers : "당첨 번호를 입력해 주세요.\n", + inputWinningNumbers : "\n당첨 번호를 입력해 주세요.\n", + inputBonusNumber : "\n보너스 번호를 입력해 주세요.\n", }; export const OUTPUT_MESSAGE = { @@ -14,4 +15,5 @@ export const ERROR_MESSAGE = { lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다.", lottoTypeError : "[ERROR] 로또 번호는 자연수입니다.", + bonusLengthError : "[ERROR] 보너스 번호는 1개여야 합니다." }; \ No newline at end of file diff --git a/src/validator/lotto-bonus-validator.js b/src/validator/lotto-bonus-validator.js new file mode 100644 index 0000000000..2143ae6c93 --- /dev/null +++ b/src/validator/lotto-bonus-validator.js @@ -0,0 +1,25 @@ +import { ERROR_MESSAGE } from "../constants/constants.js"; + +class LottoBonusValidator { + static bonusLengthValidation(numbers) { + if (numbers.length !== 1) { + throw new Error(ERROR_MESSAGE.bonusLengthError); + } + } + + static bonusRangeValidation(number) { + const isOutOfRange = number < 1 || number > 45; + if (isOutOfRange) { + throw new Error(ERROR_MESSAGE.lottoRangeError); + } + } + + static bonusTypeValidation(number) { + const isTypeValid = Number.isInteger(number); + if (!isTypeValid) { + throw new Error(ERROR_MESSAGE.lottoTypeError); + } + } +} + +export default LottoBonusValidator; diff --git a/src/view/input-view.js b/src/view/input-view.js index 90fe0fdc8a..bf4d03ac0b 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -2,6 +2,7 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; import InputValidator from "../validator/input-validator.js"; import LottoValidator from "../validator/lotto-validator.js"; +import LottoBonusValidator from "../validator/lotto-bonus-validator.js"; class InputView { async readPurchaseAmount() { @@ -20,7 +21,13 @@ class InputView { return winningNumbers; } - async readBonusNumber() {} + async readBonusNumber() { + const bonusNumber = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); + LottoBonusValidator.bonusLengthValidation(bonusNumber); + LottoBonusValidator.bonusRangeValidation(bonusNumber); + LottoBonusValidator.bonusTypeValidation(bonusNumber); + return bonusNumber; + } } export default InputView; \ No newline at end of file From ac618d127fc6287df1ab4da97c615f44ed198258 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 19:41:54 +0900 Subject: [PATCH 44/53] =?UTF-8?q?fix=20:=20=EB=A1=9C=EB=98=90=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=EC=8B=9C?= =?UTF-8?q?=20=EB=B0=B0=EC=97=B4=20=ED=98=95=ED=83=9C=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=88=EC=97=AC=EC=84=9C=20=EB=B0=9C=EC=83=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 2 ++ src/view/input-view.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index 5c7625ba9a..857fae5a64 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -16,6 +16,8 @@ class LottoController { let perchaseNumber = await this.#inputView.readPurchaseAmount(); let myLotto = new MyLotto(perchaseNumber); this.#outputView.printMyLotto(perchaseNumber, myLotto); + let winningNumbers = await this.#inputView.readWinningNumber(); + let bonusNumber = await this.#inputView.readBonusNumber(); } } diff --git a/src/view/input-view.js b/src/view/input-view.js index bf4d03ac0b..89614cea3a 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -13,7 +13,8 @@ class InputView { } async readWinningNumber() { - const winningNumbers = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); + const input = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); + const winningNumbers = input.split(",").map(Number); LottoValidator.lottoLengthValidation(winningNumbers); LottoValidator.lottoDuplicatedValidation(winningNumbers); LottoValidator.lottoRangeValidation(winningNumbers); From 6bfd6c1e37c7d92d8d239bc8cb2dad705c2401a6 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 19:51:47 +0900 Subject: [PATCH 45/53] =?UTF-8?q?fix=20:=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EC=8B=9C=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=8B=A4=ED=8C=A8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/lotto-bonus-validator.js | 4 ++-- src/view/input-view.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/validator/lotto-bonus-validator.js b/src/validator/lotto-bonus-validator.js index 2143ae6c93..e271a4856b 100644 --- a/src/validator/lotto-bonus-validator.js +++ b/src/validator/lotto-bonus-validator.js @@ -1,8 +1,8 @@ import { ERROR_MESSAGE } from "../constants/constants.js"; class LottoBonusValidator { - static bonusLengthValidation(numbers) { - if (numbers.length !== 1) { + static bonusLengthValidation(number) { + if (number.length !== 1) { throw new Error(ERROR_MESSAGE.bonusLengthError); } } diff --git a/src/view/input-view.js b/src/view/input-view.js index 89614cea3a..08fa3ca297 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -7,6 +7,7 @@ import LottoBonusValidator from "../validator/lotto-bonus-validator.js"; class InputView { async readPurchaseAmount() { const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); + InputValidator.purchaseRangeValidation(inputPrice); InputValidator.inputPurchaseValidation(inputPrice); return inputPrice / 1000; @@ -15,6 +16,7 @@ class InputView { async readWinningNumber() { const input = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); const winningNumbers = input.split(",").map(Number); + LottoValidator.lottoLengthValidation(winningNumbers); LottoValidator.lottoDuplicatedValidation(winningNumbers); LottoValidator.lottoRangeValidation(winningNumbers); @@ -23,11 +25,13 @@ class InputView { } async readBonusNumber() { - const bonusNumber = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); + const input = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); + const bonusNumber = input.split(",").map(Number); + LottoBonusValidator.bonusLengthValidation(bonusNumber); LottoBonusValidator.bonusRangeValidation(bonusNumber); - LottoBonusValidator.bonusTypeValidation(bonusNumber); - return bonusNumber; + LottoBonusValidator.bonusTypeValidation(bonusNumber[0]); + return bonusNumber[0]; } } From adf5eacbc59bb033da490ba8ef30f0f983c937fb Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 20:39:14 +0900 Subject: [PATCH 46/53] =?UTF-8?q?docs=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EC=99=84=EB=A3=8C=EC=83=81=ED=83=9C=20=EA=B0=B1?= =?UTF-8?q?=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/readme.md b/docs/readme.md index 3d34383fd2..deb7eb780b 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -110,19 +110,19 @@ 로또 번호가 자연수가 아닐 경우 예외 처리한다. - + 당첨 번호를 입력 받는다. 번호는 쉼표(,)를 기준으로 구분한다. - + 보너스 번호를 입력받는다. - + 로또 번호는 1-45사이 숫자이며 아닐 경우 예외 처리한다. - + 로또 번호가 중복되는 숫자일 경우 예외 처리한다. @@ -138,11 +138,11 @@ 테스트 - + 발행한 로또 수량 및 번호를 출력한다. - + 로또 번호는 오름차순으로 정렬하여 보여준다. From 441e954bc9f2547e9c8335408256b506151f5e21 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 21:04:02 +0900 Subject: [PATCH 47/53] =?UTF-8?q?refactor=20:=20Lotto=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=83=81=EC=86=8D=EB=B0=9B=EC=9D=80=20Win?= =?UTF-8?q?ningLotto=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A5=BC=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EC=84=9C=20input=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 5 ++--- src/domain/WinningLotto.js | 24 ++++++++++++++++++++++++ src/view/input-view.js | 26 ++++++++------------------ 3 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 src/domain/WinningLotto.js diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index 857fae5a64..b77e90a37a 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -2,7 +2,6 @@ import MyLotto from "../domain/MyLotto.js"; import InputView from "../view/input-view.js"; import OutputView from "../view/output-view.js"; - class LottoController { #inputView #outputView @@ -16,8 +15,8 @@ class LottoController { let perchaseNumber = await this.#inputView.readPurchaseAmount(); let myLotto = new MyLotto(perchaseNumber); this.#outputView.printMyLotto(perchaseNumber, myLotto); - let winningNumbers = await this.#inputView.readWinningNumber(); - let bonusNumber = await this.#inputView.readBonusNumber(); + + let winningLotto = await this.#inputView.readWinningLotto(); } } diff --git a/src/domain/WinningLotto.js b/src/domain/WinningLotto.js new file mode 100644 index 0000000000..df342247b1 --- /dev/null +++ b/src/domain/WinningLotto.js @@ -0,0 +1,24 @@ +import Lotto from "./Lotto.js"; +import LottoBonusValidator from "../validator/lotto-bonus-validator.js"; + +class WinningLotto extends Lotto { + #bonusNumber + + constructor(winningNumbers, bonusNumber) { + super(winningNumbers); + this.#bonusValidate(bonusNumber); + this.#bonusNumber = bonusNumber; + } + + #bonusValidate(bonusNumber){ + LottoBonusValidator.bonusLengthValidation(bonusNumber); + LottoBonusValidator.bonusRangeValidation(bonusNumber); + LottoBonusValidator.bonusTypeValidation(bonusNumber[0]); + } + + getBonusNumber() { + return this.#bonusNumber[0]; + } +} + +export default WinningLotto; \ No newline at end of file diff --git a/src/view/input-view.js b/src/view/input-view.js index 08fa3ca297..a28dc6d4d1 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -1,8 +1,7 @@ import { Console } from "@woowacourse/mission-utils"; import { INPUT_MESSAGE } from "../constants/constants.js"; import InputValidator from "../validator/input-validator.js"; -import LottoValidator from "../validator/lotto-validator.js"; -import LottoBonusValidator from "../validator/lotto-bonus-validator.js"; +import WinningLotto from "../domain/WinningLotto.js"; class InputView { async readPurchaseAmount() { @@ -13,25 +12,16 @@ class InputView { return inputPrice / 1000; } - async readWinningNumber() { - const input = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); - const winningNumbers = input.split(",").map(Number); + async readWinningLotto() { + const readWinningNumber = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); + const winningNumbers = readWinningNumber.split(",").map(Number); - LottoValidator.lottoLengthValidation(winningNumbers); - LottoValidator.lottoDuplicatedValidation(winningNumbers); - LottoValidator.lottoRangeValidation(winningNumbers); - LottoValidator.lottoTypeValidation(winningNumbers); - return winningNumbers; - } + const readBonusNumber = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); + const bonusNumber = readBonusNumber.split(",").map(Number); - async readBonusNumber() { - const input = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); - const bonusNumber = input.split(",").map(Number); + const winningLotto = new WinningLotto(winningNumbers, bonusNumber); - LottoBonusValidator.bonusLengthValidation(bonusNumber); - LottoBonusValidator.bonusRangeValidation(bonusNumber); - LottoBonusValidator.bonusTypeValidation(bonusNumber[0]); - return bonusNumber[0]; + return winningLotto; } } From e3b2ab2e9de8824f4cc7b3797550aa166ac47073 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 21:05:08 +0900 Subject: [PATCH 48/53] =?UTF-8?q?style=20:=20=EC=84=B8=EB=AF=B8=EC=BD=9C?= =?UTF-8?q?=EB=A1=A0=20=EB=88=84=EB=9D=BD=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 4 ++-- src/domain/WinningLotto.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index b77e90a37a..31e297a59a 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -3,8 +3,8 @@ import InputView from "../view/input-view.js"; import OutputView from "../view/output-view.js"; class LottoController { - #inputView - #outputView + #inputView; + #outputView; constructor() { this.#inputView = new InputView(); diff --git a/src/domain/WinningLotto.js b/src/domain/WinningLotto.js index df342247b1..1ad19c3223 100644 --- a/src/domain/WinningLotto.js +++ b/src/domain/WinningLotto.js @@ -2,7 +2,7 @@ import Lotto from "./Lotto.js"; import LottoBonusValidator from "../validator/lotto-bonus-validator.js"; class WinningLotto extends Lotto { - #bonusNumber + #bonusNumber; constructor(winningNumbers, bonusNumber) { super(winningNumbers); From 759fdd3a2e334db604f831da7f9f19bbaeafdb8f Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 21:18:18 +0900 Subject: [PATCH 49/53] =?UTF-8?q?feat=20:=20=EC=B6=9C=EB=A0=A5=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=83=81=EC=88=98=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 597fe335c4..5ade2bb8bb 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -6,6 +6,13 @@ export const INPUT_MESSAGE = { export const OUTPUT_MESSAGE = { printPurchaseNumber : (count) => `\n${count}개 구매했습니다.`, + printWinningStatistics : "\n당첨 통계\n---\n", + printFifth : (count) => `3개 일치 (5,000원) - ${count}개\n`, + printFourth : (count) => `4개 일치 (50,000원) - ${count}개\n`, + printThird : (count) => `5개 일치 (1,500,000원) - ${count}개\n`, + printSecond : (count) => `5개 일치, 보너스 볼 일치 (30,000,000원) - ${count}개\n`, + printFirst : (count) => `6개 일치 (2,000,000,000원) - ${count}개\n`, + printRateReturn : (rate) => `총 수익률은 ${rate}%입니다.`, }; export const ERROR_MESSAGE = { @@ -15,5 +22,5 @@ export const ERROR_MESSAGE = { lottoDuplicatedError : "[ERROR] 로또 번호는 중복될 수 없습니다.", lottoRangeError : "[ERROR] 로또 번호의 범위는 1~45 폐구간 입니다.", lottoTypeError : "[ERROR] 로또 번호는 자연수입니다.", - bonusLengthError : "[ERROR] 보너스 번호는 1개여야 합니다." + bonusLengthError : "[ERROR] 보너스 번호는 1개여야 합니다.", }; \ No newline at end of file From ecf5309f67c6cf5b1568ad3502c4bf028ad20f5a Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 22:41:36 +0900 Subject: [PATCH 50/53] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=98=90=EC=9D=98=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 3 ++ src/domain/LottoResult.js | 52 ++++++++++++++++++++++++++++++ src/domain/MyLotto.js | 4 +++ src/view/output-view.js | 4 +++ 4 files changed, 63 insertions(+) create mode 100644 src/domain/LottoResult.js diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index 31e297a59a..6978fc96bb 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -14,9 +14,12 @@ class LottoController { async play() { let perchaseNumber = await this.#inputView.readPurchaseAmount(); let myLotto = new MyLotto(perchaseNumber); + this.#outputView.printMyLotto(perchaseNumber, myLotto); let winningLotto = await this.#inputView.readWinningLotto(); + + this.#outputView.printResult(myLotto, winningLotto); } } diff --git a/src/domain/LottoResult.js b/src/domain/LottoResult.js new file mode 100644 index 0000000000..8ef13e2651 --- /dev/null +++ b/src/domain/LottoResult.js @@ -0,0 +1,52 @@ +class LottoResult{ + #myLotto; + #winningLotto; + #matching; + #matchReward; + + constructor(myLotto, winningLotto) { + this.#myLotto = myLotto; + this.#winningLotto = winningLotto; + this.#matching = [0, 0, 0, 0, 0]; + this.#matchReward = [5000, 50000, 1500000, 30000000, 2000000000]; + this.#compareLotto(); + } + + #updateMatch(match, isHave) { + switch(match){ + case 3 : this.#matching[0]++; break; + case 4 : this.#matching[1]++; break; + case 6 : this.#matching[4]++; break; + } + if (match == 5 && !isHave){ + this.#matching[2]++; + } + if (match == 5 && isHave){ + this.#matching[3]++; + } + } + + #compareLotto() { + for (let lotto of this.#myLotto.getMyLottos()){ + let match = lotto.getNumbers().filter(element => this.#winningLotto.getNumbers().includes(element)); + this.#updateMatch(match.length, lotto.getNumbers().includes(this.#winningLotto.getBonusNumber())); + } + } + + calculateRateResult() { + let purchaseAmount = this.#myLotto.getLottoSize() * 1000; + let reward = this.#matching.reduce((sum, value, index) => { + return sum + (value * this.#matchReward[index]); + }, 0); + + return reward/purchaseAmount; + } + + getMatching() { + return this.#matching; + } + + +} + +export default LottoResult; \ No newline at end of file diff --git a/src/domain/MyLotto.js b/src/domain/MyLotto.js index ce34af240e..01ded3557b 100644 --- a/src/domain/MyLotto.js +++ b/src/domain/MyLotto.js @@ -19,6 +19,10 @@ class MyLotto { getMyLottos() { return this.#lottos; } + + getLottoSize() { + return this.#lottos.length; + } } export default MyLotto; \ No newline at end of file diff --git a/src/view/output-view.js b/src/view/output-view.js index db01a4267d..1ad0e58a1f 100644 --- a/src/view/output-view.js +++ b/src/view/output-view.js @@ -1,6 +1,8 @@ import { OUTPUT_MESSAGE } from "../constants/constants.js"; +import LottoResult from "../domain/LottoResult.js"; import { Console } from "@woowacourse/mission-utils"; + class OutputView { printMyLotto(perchaseNumber, myLotto) { Console.print(OUTPUT_MESSAGE.printPurchaseNumber(perchaseNumber)); @@ -9,6 +11,8 @@ class OutputView { Console.print(element.getNumbers()); } } + + printResult(myLotto, winningLotto) {} }; export default OutputView; \ No newline at end of file From 102c3822caf44f30e48f3e054712ab8e4e9ef5ff Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 23:00:21 +0900 Subject: [PATCH 51/53] =?UTF-8?q?feat=20:=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoResult.js | 2 +- src/view/output-view.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/domain/LottoResult.js b/src/domain/LottoResult.js index 8ef13e2651..e1e67b61ea 100644 --- a/src/domain/LottoResult.js +++ b/src/domain/LottoResult.js @@ -39,7 +39,7 @@ class LottoResult{ return sum + (value * this.#matchReward[index]); }, 0); - return reward/purchaseAmount; + return (reward/purchaseAmount).toFixed(1); } getMatching() { diff --git a/src/view/output-view.js b/src/view/output-view.js index 1ad0e58a1f..bdeb10b40b 100644 --- a/src/view/output-view.js +++ b/src/view/output-view.js @@ -12,7 +12,17 @@ class OutputView { } } - printResult(myLotto, winningLotto) {} + printResult(myLotto, winningLotto) { + let lottoResult = new LottoResult(myLotto, winningLotto); + let match = lottoResult.getMatching(); + Console.print(OUTPUT_MESSAGE.printWinningStatistics); + Console.print(OUTPUT_MESSAGE.printFifth(match[0])); + Console.print(OUTPUT_MESSAGE.printFourth(match[1])); + Console.print(OUTPUT_MESSAGE.printThird(match[2])); + Console.print(OUTPUT_MESSAGE.printSecond(match[3])); + Console.print(OUTPUT_MESSAGE.printFirst(match[4])); + Console.print(OUTPUT_MESSAGE.printRateReturn(lottoResult.calculateRateResult())); + } }; export default OutputView; \ No newline at end of file From 6c8ba11ba3fe94cce436925294ec4a260fa576af Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 23:02:33 +0900 Subject: [PATCH 52/53] =?UTF-8?q?style=20:=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EC=83=81=EC=88=98=20=EA=B0=9C=ED=96=89=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants/constants.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/constants/constants.js b/src/constants/constants.js index 5ade2bb8bb..902c30c7aa 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -6,12 +6,12 @@ export const INPUT_MESSAGE = { export const OUTPUT_MESSAGE = { printPurchaseNumber : (count) => `\n${count}개 구매했습니다.`, - printWinningStatistics : "\n당첨 통계\n---\n", - printFifth : (count) => `3개 일치 (5,000원) - ${count}개\n`, - printFourth : (count) => `4개 일치 (50,000원) - ${count}개\n`, - printThird : (count) => `5개 일치 (1,500,000원) - ${count}개\n`, - printSecond : (count) => `5개 일치, 보너스 볼 일치 (30,000,000원) - ${count}개\n`, - printFirst : (count) => `6개 일치 (2,000,000,000원) - ${count}개\n`, + printWinningStatistics : "\n당첨 통계\n---", + printFifth : (count) => `3개 일치 (5,000원) - ${count}개`, + printFourth : (count) => `4개 일치 (50,000원) - ${count}개`, + printThird : (count) => `5개 일치 (1,500,000원) - ${count}개`, + printSecond : (count) => `5개 일치, 보너스 볼 일치 (30,000,000원) - ${count}개`, + printFirst : (count) => `6개 일치 (2,000,000,000원) - ${count}개`, printRateReturn : (rate) => `총 수익률은 ${rate}%입니다.`, }; From 122cd08458ca805ca852f9760c62f7ced42f8918 Mon Sep 17 00:00:00 2001 From: leelsj2007 Date: Wed, 8 Nov 2023 23:46:24 +0900 Subject: [PATCH 53/53] =?UTF-8?q?fix=20:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=EC=97=90=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=90=A0=20=EA=B2=BD=EC=9A=B0=20=EC=9E=98=EB=AA=BB=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=ED=95=9C=20=EB=B6=80=EB=B6=84=20=EB=B6=80=ED=84=B0=20?= =?UTF-8?q?=EC=9E=AC=EC=8B=9C=EC=9E=91=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/lotto-controller.js | 2 +- src/view/input-view.js | 32 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/controller/lotto-controller.js b/src/controller/lotto-controller.js index 6978fc96bb..94799f1430 100644 --- a/src/controller/lotto-controller.js +++ b/src/controller/lotto-controller.js @@ -14,7 +14,7 @@ class LottoController { async play() { let perchaseNumber = await this.#inputView.readPurchaseAmount(); let myLotto = new MyLotto(perchaseNumber); - + this.#outputView.printMyLotto(perchaseNumber, myLotto); let winningLotto = await this.#inputView.readWinningLotto(); diff --git a/src/view/input-view.js b/src/view/input-view.js index a28dc6d4d1..350028fc49 100644 --- a/src/view/input-view.js +++ b/src/view/input-view.js @@ -5,23 +5,35 @@ import WinningLotto from "../domain/WinningLotto.js"; class InputView { async readPurchaseAmount() { - const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); + try{ + const inputPrice = await Console.readLineAsync(INPUT_MESSAGE.inputPurchaseAmount); - InputValidator.purchaseRangeValidation(inputPrice); - InputValidator.inputPurchaseValidation(inputPrice); - return inputPrice / 1000; + InputValidator.purchaseRangeValidation(inputPrice); + InputValidator.inputPurchaseValidation(inputPrice); + return inputPrice / 1000; + } + catch(error){ + Console.print(error); + await this.readPurchaseAmount(); + } } async readWinningLotto() { - const readWinningNumber = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); - const winningNumbers = readWinningNumber.split(",").map(Number); + try{ + const readWinningNumber = await Console.readLineAsync(INPUT_MESSAGE.inputWinningNumbers); + const winningNumbers = readWinningNumber.split(",").map(Number); - const readBonusNumber = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); - const bonusNumber = readBonusNumber.split(",").map(Number); + const readBonusNumber = await Console.readLineAsync(INPUT_MESSAGE.inputBonusNumber); + const bonusNumber = readBonusNumber.split(",").map(Number); - const winningLotto = new WinningLotto(winningNumbers, bonusNumber); + const winningLotto = new WinningLotto(winningNumbers, bonusNumber); - return winningLotto; + return winningLotto; + } + catch(error){ + Console.print(error); + await this.readWinningLotto(); + } } }