From 23414b1726597fecc9930b49870926100eebfae6 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Fri, 15 Mar 2024 12:37:45 +0900
Subject: [PATCH 01/47] Feat : First commit
---
docs/README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/docs/README.md b/docs/README.md
index e69de29..a1b78e2 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -0,0 +1 @@
+first commit
\ No newline at end of file
From 4027ed13f9ff1b2c2a94113f5b42a677805af874 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 11:02:14 +0900
Subject: [PATCH 02/47] =?UTF-8?q?Feat(codeStyleConfig)=20:=20=EC=9E=90?=
=?UTF-8?q?=EB=B0=94=20=EC=BD=94=EB=93=9C=20=EC=BB=A8=EB=B2=A4=EC=85=98=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
---
.idea/codeStyles/codeStyleConfig.xml | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 .idea/codeStyles/codeStyleConfig.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..38d3018
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
From d38b158adb043386b14476003508596189d5bfb4 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 11:03:26 +0900
Subject: [PATCH 03/47] =?UTF-8?q?docs(README.md)=20:=20=ED=8C=A8=ED=82=A4?=
=?UTF-8?q?=EC=A7=80=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EA=B5=AC?=
=?UTF-8?q?=EC=A1=B0=20=EC=84=A4=EA=B3=84=EC=99=80=20=EC=97=AD=ED=95=A0=20?=
=?UTF-8?q?=EB=B6=80=EC=97=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/README.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 1 deletion(-)
diff --git a/docs/README.md b/docs/README.md
index a1b78e2..0872ecf 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1 +1,84 @@
-first commit
\ No newline at end of file
+# JAVA - LOTTO
+
+https://github.com/TEAM-ALOM/java-lotto
+
+## ๐๏ธ Package ๊ตฌ์กฐ(MVC)
+
+### **Model**
+
+#### Lotto
+
+- ์ญํ : ๋ก๋์ ์ค์ง์ ๋ฐ์ดํฐ
+ - [ ]
+
+#### Lottos
+
+- ์ญํ : ๊ตฌ๋งคํ ๋ก๋๋ค์ ๋ฌถ์ ์ค์ง์ ๋ฐ์ดํฐ
+
+#### LottoGenerator
+
+- ์ญํ : Lotto ์์ฑ
+
+#### LottosWinningChecker
+
+- ์ญํ : Lottos์ ๋น์ฒจ ๊ณ์ฐ
+
+#### LottosStatus
+
+- ์ญํ : Lottos์ ๋น์ณ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ์ค์ง์ ๋ฐ์ดํฐ
+
+#### WinningNumbers
+
+- ์ญํ : ๋น์ฒจ ๋ฒํธ๋ค(ํ๋์ ๋ก๋ ๊ฐ์ฒด)์ ์ค์ง์ ๋ฐ์ดํฐ
+
+#### WinningType
+
+- ์ญํ : ๋ฑ์ ๋ณ ๋น์ฒจ ์กฐ๊ฑด ๋ชฉ๋ก์ ์ค์ง์ ๋ฐ์ดํฐ
+
+### Controller
+
+#### LottoSystemController
+
+- ์ญํ : ๋ก๋ ์์คํ
์ ์คํ
+
+### **View**
+
+#### InputView
+
+- ์ญํ : ์ฌ์ฉ์์ ์
๋ ฅ์ ๋ฐ๋๋ค.
+ - [ ] ๋ก๋ ๊ตฌ์
๊ธ์ก ์
๋ ฅ
+ - [ ] 1000์ ๋จ์๋ก ์
๋ ฅ
+ - [ ] ๋๋์ด ๋จ์ด์ง์ง ์์ ๊ฒฝ์ฐ ์์ธ
+ - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ
+ - ๋ฒํธ๋ ์ผํ๋ก ๊ตฌ๋ถ
+ - [ ] ๋ณด๋์ค ๋ฒํธ ์
๋ ฅ
+
+#### OutputView
+
+- ์ญํ : ์ถ๋ ฅํ๋ค.
+ - [ ] ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] ๊ตฌ๋งค ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] ๊ตฌ๋งคํ Lottos๋ฅผ ์ถ๋ ฅ
+ - [ ] ๋น์ฒจ ํต๊ณ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] 3๊ฐ ์ผ์น ~ 6๊ฐ ์ผ์น ๋ณ ๊ธ์ก๊ณผ ๋น์ฒจ ๊ฐ์๋ฅผ ์ถ๋ ฅ
+ - [ ] ์์ต๋ฅ ์ถ๋ ฅ
+ - [ ] ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] ์
๋ ฅ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] ๊ตฌ์
๊ธ์ก ์
๋ ฅ ๋ฌธ๊ตฌ
+ - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ ๋ฌธ๊ตฌ
+ - [ ] ๋ณด๋์ค ๋ฒํธ ์
๋ ฅ ๋ฌธ๊ตฌ
+ - [ ] ์๋ฌ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [ ] [ERROR]๋ก ์์ํด์ผํ๋ค.
+
+### **Validation** (๋ฃ์๊น ๊ณ ๋ฏผ์ค)
+
+- ์ญํ : ๊ฐ ๊ณ์ธต๋ณ ์กฐ๊ฑด์ ๋ง๋ ๊ฒ์ฆ ์ํ ๋ฐ ์์ธ ์ฒ๋ฆฌ
+
+#### ViewValidation
+
+#### ControllerValidation
+
+#### ModelValidation
+
+## Test
+
From 4af8198c56a5a668933523fab1cd72e8ae6732db Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:40:09 +0900
Subject: [PATCH 04/47] =?UTF-8?q?docs(README.md)=20:=20=EC=97=AD=ED=95=A0?=
=?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20validation=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
---
docs/README.md | 38 ++++++++++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 0872ecf..53b6f60 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -6,30 +6,33 @@ https://github.com/TEAM-ALOM/java-lotto
### **Model**
+#### LottoUser
+
+- ์ญํ : (int)`money`, `Lottos`๊ณผ `LottosWinningStatus`๋ฅผ ๊ฐ์ง๊ณ ์๋ ๊ฐ์ฒด
+
#### Lotto
- ์ญํ : ๋ก๋์ ์ค์ง์ ๋ฐ์ดํฐ
- - [ ]
#### Lottos
-- ์ญํ : ๊ตฌ๋งคํ ๋ก๋๋ค์ ๋ฌถ์ ์ค์ง์ ๋ฐ์ดํฐ
+- ์ญํ : ๊ตฌ๋งคํ `Lotto`๋ค์ ๋ฌถ์(`List`) ์ค์ง์ ๋ฐ์ดํฐ
#### LottoGenerator
-- ์ญํ : Lotto ์์ฑ
+- ์ญํ : `LottoUser.money`์ ๋ฐ๋ผ `Lotto`๋ค์ ์์ฑ
#### LottosWinningChecker
-- ์ญํ : Lottos์ ๋น์ฒจ ๊ณ์ฐ
+- ์ญํ : `Lottos`์ ๋น์ฒจ ๊ณ์ฐ
-#### LottosStatus
+#### LottosWinningStatus
-- ์ญํ : Lottos์ ๋น์ณ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ์ค์ง์ ๋ฐ์ดํฐ
+- ์ญํ : `WinningNumbers`,`WinningType`๋ฅผ ๋ฐํ์ผ๋ก `Lottos`์ ๋น์ณ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ์ค์ง์ ๋ฐ์ดํฐ
#### WinningNumbers
-- ์ญํ : ๋น์ฒจ ๋ฒํธ๋ค(ํ๋์ ๋ก๋ ๊ฐ์ฒด)์ ์ค์ง์ ๋ฐ์ดํฐ
+- ์ญํ : ๋ณด๋์ค ๋ฒํธ์ ๋น์ฒจ ๋ฒํธ๋ค(ํ๋์ ๋ก๋ ๊ฐ์ฒด)์ ์ค์ง์ ๋ฐ์ดํฐ
#### WinningType
@@ -76,9 +79,28 @@ https://github.com/TEAM-ALOM/java-lotto
#### ViewValidation
+- ์ญํ : ์ฌ์ฉ์ ์
์ถ๋ ฅ์ ๊ดํ ๊ฒ์ฆ
+ - [ ] InputView
+ - [ ] ๋ก๋ ๊ตฌ์
๊ธ์ก
+ - [ ] ์ซ์์ธ๊ฐ?
+ - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ
+ - [ ] ์ผํ๋ก ๊ตฌ๋ถ์ด ๋์๋
+ - [ ] ์ผํ๋ก ์์ํ๋๊ฐ
+ - [ ] ์ผํ๋ก ๋๋๋๊ฐ
+ - [ ] ๋ณด๋์ค ๋ฒํธ
+ - [ ] ์ซ์ ์ธ๊ฐ
+ - [ ] OutputView
+ - [ ] ๊ตฌ๋งค ๋ก๋ ์ถ๋ ฅ
+ - [ ] ๋น์ฒจ ํต๊ณ ์ถ๋ ฅ
+
#### ControllerValidation
#### ModelValidation
-## Test
+- ์ญํ : ๊ฐ ๋ชจ๋ธ ๊ฐ์ฒด์ ๊ดํ ๊ฒ์ฆ
+#### ErrorMessage
+
+- ์ญํ : ์๋ฌ ๋ฉ์ธ์ง ๋ชจ์
+
+## Test
From 220545c3ac865f45426dbd5c857b09f2ef3ece7b Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:41:19 +0900
Subject: [PATCH 05/47] =?UTF-8?q?Feat(InputView)=20:=20=EA=B5=AC=EB=A7=A4?=
=?UTF-8?q?=20=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?=
=?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/java/lotto/view/InputView.java | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 src/main/java/lotto/view/InputView.java
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
new file mode 100644
index 0000000..3ec9b11
--- /dev/null
+++ b/src/main/java/lotto/view/InputView.java
@@ -0,0 +1,23 @@
+package lotto.view;
+
+import org.kokodak.Console;
+
+public class InputView {
+ public static int moneyForPurchaseInput() {
+ String moneyForPurchase = Console.readLine();
+ return changeInputToInt(moneyForPurchase);
+ }
+
+ private static int changeInputToInt(String moneyForPurchase) {
+ checkPossibleChangeToInt(moneyForPurchase);
+ return Integer.parseInt(moneyForPurchase);
+ }
+
+ private static void checkPossibleChangeToInt(String moneyForPurchase) {
+ try {
+ Integer.parseInt(moneyForPurchase);
+ } catch (NumberFormatException e) {
+ throw new IllegalStateException("exception ๋ฌธ๊ตฌ");
+ }
+ }
+}
From ad45736b85b9e853ecd142fa97a76beb3b3a1c10 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:41:41 +0900
Subject: [PATCH 06/47] =?UTF-8?q?test(InputViewTest)=20:=20=EA=B5=AC?=
=?UTF-8?q?=EB=A7=A4=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0?=
=?UTF-8?q?=EB=8A=A5=20test=20=EC=9E=91=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/test/java/lotto/view/InputViewTest.java | 74 +++++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 src/test/java/lotto/view/InputViewTest.java
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
new file mode 100644
index 0000000..edde5a0
--- /dev/null
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -0,0 +1,74 @@
+package lotto.view;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import org.junit.jupiter.api.Test;
+
+class InputViewTest {
+
+ @Test
+ void ๊ตฌ์
๊ธ์ก_์ ์_์
๋ ฅ() {
+ String input = "1000";
+ setInput(input);
+ int money = InputView.moneyForPurchaseInput();
+ assertThat(input).isEqualTo(String.valueOf(money));
+ }
+
+ private static void setInput(String input) {
+ OutputStream out = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(out));
+ InputStream in = new ByteArrayInputStream(input.getBytes());
+ System.setIn(in);
+ }
+
+ @Test
+ void ๊ตฌ์
๊ธ์ก_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+ String input = "english";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.moneyForPurchaseInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์");
+ }
+
+ @Test
+ void ๋น์ฒจ๋ฒํธ_์ ์_์
๋ ฅ() {
+
+ }
+
+ @Test
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+
+ }
+
+ @Test
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ๋๋ฝ() {
+
+ }
+
+ @Test
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ์ค๋ณต() {
+
+ }
+
+ @Test
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ฒ์_๋๋_๋์_์ผํ() {
+
+ }
+
+ @Test
+ void ๋ณด๋์ค๋ฒํธ_์ ์_์
๋ ฅ() {
+
+ }
+
+ @Test
+ void ๋ณด๋์ค๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+
+ }
+
+}
\ No newline at end of file
From f1d63d865fe630743d73e8643f18c6b582dc6d82 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:49:34 +0900
Subject: [PATCH 07/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20=EC=97=90?=
=?UTF-8?q?=EB=9F=AC=EB=A9=94=EC=84=B8=EC=A7=80=20enum=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/java/lotto/validation/ErrorMessage.java | 15 +++++++++++++++
src/test/java/lotto/view/InputViewTest.java | 3 ++-
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/lotto/validation/ErrorMessage.java
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
new file mode 100644
index 0000000..61522e8
--- /dev/null
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -0,0 +1,15 @@
+package lotto.validation;
+
+public enum ErrorMessage {
+ MONEY_FOR_PURCHASE_NOT_NUMBER("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์");
+
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
index edde5a0..592a0ec 100644
--- a/src/test/java/lotto/view/InputViewTest.java
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -8,6 +8,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import lotto.validation.ErrorMessage;
import org.junit.jupiter.api.Test;
class InputViewTest {
@@ -33,7 +34,7 @@ private static void setInput(String input) {
setInput(input);
assertThatThrownBy(() -> InputView.moneyForPurchaseInput())
.isInstanceOf(IllegalStateException.class)
- .hasMessage("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์");
+ .hasMessage(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
@Test
From a508587516545401b55269e6acc42206f7e1f8c4 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Tue, 19 Mar 2024 16:50:39 +0900
Subject: [PATCH 08/47] =?UTF-8?q?Feat(InputView)=20:=20=EA=B8=88=EC=95=A1?=
=?UTF-8?q?=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=99=84=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/InputView.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
index 3ec9b11..9d81452 100644
--- a/src/main/java/lotto/view/InputView.java
+++ b/src/main/java/lotto/view/InputView.java
@@ -1,5 +1,6 @@
package lotto.view;
+import lotto.validation.ErrorMessage;
import org.kokodak.Console;
public class InputView {
@@ -17,7 +18,7 @@ private static void checkPossibleChangeToInt(String moneyForPurchase) {
try {
Integer.parseInt(moneyForPurchase);
} catch (NumberFormatException e) {
- throw new IllegalStateException("exception ๋ฌธ๊ตฌ");
+ throw new IllegalStateException(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
}
}
From 1d43200d7cc1c79e340ec4b7d103b4e2fdb1aefd Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:13:53 +0900
Subject: [PATCH 09/47] =?UTF-8?q?Feat(InputView)=20:=20=EB=8B=B9=EC=B2=A8?=
=?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/InputView.java | 31 +++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
index 9d81452..7a46feb 100644
--- a/src/main/java/lotto/view/InputView.java
+++ b/src/main/java/lotto/view/InputView.java
@@ -1,6 +1,12 @@
package lotto.view;
-import lotto.validation.ErrorMessage;
+import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
import org.kokodak.Console;
public class InputView {
@@ -18,7 +24,28 @@ private static void checkPossibleChangeToInt(String moneyForPurchase) {
try {
Integer.parseInt(moneyForPurchase);
} catch (NumberFormatException e) {
- throw new IllegalStateException(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ throw new IllegalStateException(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ }
+ }
+
+ private static void checkNotExistStartAndEndComma(String winningNumbers) {
+ if (winningNumbers.startsWith(",")) {
+ throw new IllegalStateException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
+ }
+ if (winningNumbers.endsWith(",")) {
+ throw new IllegalStateException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
}
}
+
+ public static List winningNumbersInput() {
+ String winningNumbers = Console.readLine();
+ checkNotExistStartAndEndComma(winningNumbers);
+ return readNumbersFromConsole(winningNumbers);
+ }
+
+ public static List readNumbersFromConsole(String winningNumbers) {
+
+ return Arrays.stream(winningNumbers.split(",")).map(InputView::changeInputToInt)
+ .collect(Collectors.toList());
+ }
}
From cc4931e36fbd29693b0ccdde412f53c5125f6a7b Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:14:30 +0900
Subject: [PATCH 10/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20=EB=8B=B9?=
=?UTF-8?q?=EC=B2=A8=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EC=98=88?=
=?UTF-8?q?=EC=99=B8=20=EB=AC=B8=EA=B5=AC=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/validation/ErrorMessage.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 61522e8..ec05f59 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -1,7 +1,9 @@
package lotto.validation;
public enum ErrorMessage {
- MONEY_FOR_PURCHASE_NOT_NUMBER("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์");
+ MONEY_FOR_PURCHASE_NOT_NUMBER("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์"),
+ WINNINGNUMBERS_NOT_START_WITH_COMMA("์ผํ๋ก ์์ํ ์ ์์ต๋๋ค."),
+ WINNINGNUMBERS_NOT_END_WITH_COMMA("์ผํ๋ก ๋๋ ์ ์์ต๋๋ค.");
private final String message;
From 1a6d15991518c327c4a9257bdee1b9c80f6049de Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:15:11 +0900
Subject: [PATCH 11/47] =?UTF-8?q?Test(InputViewTest)=20:=20=EB=8B=B9?=
=?UTF-8?q?=EC=B2=A8=EB=B2=88=ED=98=B8=EC=9E=85=EB=A0=A5=EA=B8=B0=EB=8A=A5?=
=?UTF-8?q?=20=EC=A0=95=EC=83=81=20=EB=B9=84=EC=A0=95=EC=83=81=20=EA=B2=BD?=
=?UTF-8?q?=EC=9A=B0=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/java/lotto/view/InputViewTest.java | 47 +++++++++++++++++----
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
index 592a0ec..46a4abc 100644
--- a/src/test/java/lotto/view/InputViewTest.java
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -1,5 +1,8 @@
package lotto.view;
+import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -8,7 +11,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
-import lotto.validation.ErrorMessage;
+import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
class InputViewTest {
@@ -34,32 +38,57 @@ private static void setInput(String input) {
setInput(input);
assertThatThrownBy(() -> InputView.moneyForPurchaseInput())
.isInstanceOf(IllegalStateException.class)
- .hasMessage(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ .hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
@Test
void ๋น์ฒจ๋ฒํธ_์ ์_์
๋ ฅ() {
-
+ String input = "1,2,3,4,5,6";
+ List rightWinningNumbers = Arrays.asList(1, 2, 3, 4, 5, 6);
+ setInput(input);
+ assertThat(rightWinningNumbers).isEqualTo(InputView.winningNumbersInput());
}
@Test
void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
-
+ String input = "1,a,3,4,5,6";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.winningNumbersInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
- @Test
- void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ๋๋ฝ() {
-
- }
+// @Test
+// void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ๋๋ฝ() {
+// String input = "1,,3,4,5,6";
+// setInput(input);
+// assertThatThrownBy(() -> InputView.winningNumbersInput())
+// .isInstanceOf(IllegalStateException.class)
+// .hasMessage(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+// }
@Test
void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ์ค๋ณต() {
-
+ String input = "1,,3,4,5,6";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.winningNumbersInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
@Test
void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ฒ์_๋๋_๋์_์ผํ() {
+ String input = ",3,4,5,6";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.winningNumbersInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
+ input = "3,4,5,6,";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.winningNumbersInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
}
@Test
From 7f4160bf7609ead01f04d4f09ba4ee6d535ced6f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:38:57 +0900
Subject: [PATCH 12/47] =?UTF-8?q?Feat(InputView)=20:=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?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/InputView.java | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
index 7a46feb..2936297 100644
--- a/src/main/java/lotto/view/InputView.java
+++ b/src/main/java/lotto/view/InputView.java
@@ -1,6 +1,7 @@
package lotto.view;
import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_DOUBLE_COMMA;
import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
@@ -15,6 +16,18 @@ public static int moneyForPurchaseInput() {
return changeInputToInt(moneyForPurchase);
}
+ public static List winningNumbersInput() {
+ String winningNumbers = Console.readLine();
+ checkRightCommaFormat(winningNumbers);
+ return readNumbersFromConsole(winningNumbers);
+ }
+
+ public static int bonusNumberInput() {
+ String bonusNumber = Console.readLine();
+ return changeInputToInt(bonusNumber);
+ }
+
+
private static int changeInputToInt(String moneyForPurchase) {
checkPossibleChangeToInt(moneyForPurchase);
return Integer.parseInt(moneyForPurchase);
@@ -28,19 +41,16 @@ private static void checkPossibleChangeToInt(String moneyForPurchase) {
}
}
- private static void checkNotExistStartAndEndComma(String winningNumbers) {
+ private static void checkRightCommaFormat(String winningNumbers) {
if (winningNumbers.startsWith(",")) {
throw new IllegalStateException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
}
if (winningNumbers.endsWith(",")) {
throw new IllegalStateException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
}
- }
-
- public static List winningNumbersInput() {
- String winningNumbers = Console.readLine();
- checkNotExistStartAndEndComma(winningNumbers);
- return readNumbersFromConsole(winningNumbers);
+ if (winningNumbers.contains(",,")) {
+ throw new IllegalStateException(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
+ }
}
public static List readNumbersFromConsole(String winningNumbers) {
From a91b071c56555ef50647eeeb072985b095f8d812 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:39:13 +0900
Subject: [PATCH 13/47] =?UTF-8?q?Test(InputViewTest)=20:=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?=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/java/lotto/view/InputViewTest.java | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
index 46a4abc..ec199f1 100644
--- a/src/test/java/lotto/view/InputViewTest.java
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -1,6 +1,7 @@
package lotto.view;
import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_DOUBLE_COMMA;
import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
import static org.assertj.core.api.Assertions.assertThat;
@@ -73,7 +74,7 @@ private static void setInput(String input) {
setInput(input);
assertThatThrownBy(() -> InputView.winningNumbersInput())
.isInstanceOf(IllegalStateException.class)
- .hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ .hasMessage(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
}
@Test
@@ -93,11 +94,19 @@ private static void setInput(String input) {
@Test
void ๋ณด๋์ค๋ฒํธ_์ ์_์
๋ ฅ() {
-
+ String input = "3";
+ setInput(input);
+ int money = InputView.bonusNumberInput();
+ assertThat(input).isEqualTo(String.valueOf(money));
}
@Test
void ๋ณด๋์ค๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+ String input = "e";
+ setInput(input);
+ assertThatThrownBy(() -> InputView.bonusNumberInput())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
From cd06328b5c34dab1f34238e0201f95bab2c91532 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Wed, 20 Mar 2024 21:39:38 +0900
Subject: [PATCH 14/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20=EB=B3=B4?=
=?UTF-8?q?=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20?=
=?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=AC=B8=EA=B5=AC=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/validation/ErrorMessage.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index ec05f59..13572cb 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -3,7 +3,8 @@
public enum ErrorMessage {
MONEY_FOR_PURCHASE_NOT_NUMBER("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์"),
WINNINGNUMBERS_NOT_START_WITH_COMMA("์ผํ๋ก ์์ํ ์ ์์ต๋๋ค."),
- WINNINGNUMBERS_NOT_END_WITH_COMMA("์ผํ๋ก ๋๋ ์ ์์ต๋๋ค.");
+ WINNINGNUMBERS_NOT_END_WITH_COMMA("์ผํ๋ก ๋๋ ์ ์์ต๋๋ค."),
+ WINNINGNUMBERS_NOT_DOUBLE_COMMA("์ผํ ์ฌ์ด์ ์ซ์๋ฅผ ๋ฃ์ด์ฃผ์ธ์");
private final String message;
From df0322951cc9a38543b45e30114e118fd59d63a5 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 11:15:41 +0900
Subject: [PATCH 15/47] =?UTF-8?q?Feat(Model.Domain.Lotto)=20:=20=EB=A1=9C?=
=?UTF-8?q?=EB=98=90=20=EA=B2=80=EC=A6=9D=20=EB=A9=94=EC=84=9C=EB=93=9C=20?=
=?UTF-8?q?=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Lotto.java | 20 -------
src/main/java/lotto/model/domain/Lotto.java | 65 +++++++++++++++++++++
2 files changed, 65 insertions(+), 20 deletions(-)
delete mode 100644 src/main/java/lotto/Lotto.java
create mode 100644 src/main/java/lotto/model/domain/Lotto.java
diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java
deleted file mode 100644
index 519793d..0000000
--- a/src/main/java/lotto/Lotto.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package lotto;
-
-import java.util.List;
-
-public class Lotto {
- private final List numbers;
-
- public Lotto(List numbers) {
- validate(numbers);
- this.numbers = numbers;
- }
-
- private void validate(List numbers) {
- if (numbers.size() != 6) {
- throw new IllegalArgumentException();
- }
- }
-
- // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
-}
diff --git a/src/main/java/lotto/model/domain/Lotto.java b/src/main/java/lotto/model/domain/Lotto.java
new file mode 100644
index 0000000..d2d75ed
--- /dev/null
+++ b/src/main/java/lotto/model/domain/Lotto.java
@@ -0,0 +1,65 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.LOTTO_HAS_DUPLICATED_NUMBER;
+import static lotto.validation.ErrorMessage.LOTTO_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTO_SIZE_NOT_SIX;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class Lotto {
+ private static final int MIN_LOTTO_NUMBER = 1;
+ private static final int MAX_LOTTO_NUMBER = 45;
+
+ private final List numbers;
+
+ public Lotto(List numbers) {
+ validate(numbers);
+ this.numbers = numbers;
+ }
+
+ private void validate(List numbers) {
+ checkSizeOnlySix(numbers);
+ checkNumberOutOfRange(numbers);
+ checkDuplicatedNumber(numbers);
+ }
+
+ // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+
+ private void checkSizeOnlySix(List numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(LOTTO_SIZE_NOT_SIX.getMessage());
+ }
+ }
+
+ private void checkNumberOutOfRange(List numbers) {
+ for (Integer number : numbers) {
+ if (isNumberOutOfRange(number)) {
+ throw new IllegalArgumentException(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+ }
+ }
+
+ private void checkDuplicatedNumber(List numbers) {
+ Set numbersNotDupl = new HashSet<>();
+ for (Integer number : numbers) {
+ checkAndAddNumber(numbersNotDupl, number);
+ }
+ }
+
+ private void checkAndAddNumber(Set numbersNotDupl, Integer number) {
+ if (numbersNotDupl.contains(number)) {
+ throw new IllegalArgumentException(LOTTO_HAS_DUPLICATED_NUMBER.getMessage());
+ }
+ numbersNotDupl.add(number);
+ }
+
+ private boolean isNumberOutOfRange(int number) {
+ return number < MIN_LOTTO_NUMBER || number > MAX_LOTTO_NUMBER;
+ }
+
+ public List getNumbers() {
+ return numbers;
+ }
+}
From 1f0b5cc594161a17cbdda0ddc391235aff50ce38 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 12:19:01 +0900
Subject: [PATCH 16/47] =?UTF-8?q?Test(LottoTest)=20:=20Lotto=20=ED=85=8C?=
=?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/test/java/lotto/LottoTest.java | 26 ---------
.../java/lotto/model/domain/LottoTest.java | 56 +++++++++++++++++++
2 files changed, 56 insertions(+), 26 deletions(-)
delete mode 100644 src/test/java/lotto/LottoTest.java
create mode 100644 src/test/java/lotto/model/domain/LottoTest.java
diff --git a/src/test/java/lotto/LottoTest.java b/src/test/java/lotto/LottoTest.java
deleted file mode 100644
index 14ed50f..0000000
--- a/src/test/java/lotto/LottoTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package lotto;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.List;
-import org.junit.jupiter.api.DisplayName;
-import org.junit.jupiter.api.Test;
-
-class LottoTest {
- @DisplayName("๋ก๋ ๋ฒํธ์ ๊ฐ์๊ฐ 6๊ฐ๊ฐ ๋์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
- @Test
- void createLottoByOverSize() {
- assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 6, 7)))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- @DisplayName("๋ก๋ ๋ฒํธ์ ์ค๋ณต๋ ์ซ์๊ฐ ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
- @Test
- void createLottoByDuplicatedNumber() {
- // TODO: ์ด ํ
์คํธ๊ฐ ํต๊ณผํ ์ ์๊ฒ ๊ตฌํ ์ฝ๋ ์์ฑ
- assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 5)))
- .isInstanceOf(IllegalArgumentException.class);
- }
-
- // ์๋์ ์ถ๊ฐ ํ
์คํธ ์์ฑ ๊ฐ๋ฅ
-}
diff --git a/src/test/java/lotto/model/domain/LottoTest.java b/src/test/java/lotto/model/domain/LottoTest.java
new file mode 100644
index 0000000..9117a7e
--- /dev/null
+++ b/src/test/java/lotto/model/domain/LottoTest.java
@@ -0,0 +1,56 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.LOTTO_HAS_DUPLICATED_NUMBER;
+import static lotto.validation.ErrorMessage.LOTTO_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTO_SIZE_NOT_SIX;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.List;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class LottoTest {
+ @DisplayName("๋ก๋ ๋ฒํธ์ ๊ฐ์๊ฐ 6๊ฐ๊ฐ ๋์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void createLottoByOverSize() {
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 6, 7)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_SIZE_NOT_SIX.getMessage());
+ }
+
+ @DisplayName("๋ก๋ ๋ฒํธ์ ์ค๋ณต๋ ์ซ์๊ฐ ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void createLottoByDuplicatedNumber() {
+ // TODO: ์ด ํ
์คํธ๊ฐ ํต๊ณผํ ์ ์๊ฒ ๊ตฌํ ์ฝ๋ ์์ฑ
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 5)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_HAS_DUPLICATED_NUMBER.getMessage());
+ }
+
+ // ์๋์ ์ถ๊ฐ ํ
์คํธ ์์ฑ ๊ฐ๋ฅ
+
+ @Test
+ void ๋ก๋๋ฒํธ_์ ์() {
+ new Lotto(List.of(1, 2, 3, 4, 5, 6));
+ }
+
+ @Test
+ void ๋ก๋๋ฒํธ_๋น์ ์_๊ฐฏ์_5๊ฐ_์ดํ_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_SIZE_NOT_SIX.getMessage());
+ }
+
+ @Test
+ void ๋ก๋๋ฒํธ_๋น์ ์_๋ก๋์_๋ฒ์์ด๊ณผ_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 46)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 0)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, -1)))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+}
From 5d8dc4dbe54ab25740e18eb80f5b455a70f9529f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 13:13:49 +0900
Subject: [PATCH 17/47] =?UTF-8?q?Refactor(InputView)=20:=20exception=20?=
=?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/InputView.java | 8 ++---
src/test/java/lotto/view/InputViewTest.java | 35 ++++++++++-----------
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
index 2936297..1a71801 100644
--- a/src/main/java/lotto/view/InputView.java
+++ b/src/main/java/lotto/view/InputView.java
@@ -37,19 +37,19 @@ private static void checkPossibleChangeToInt(String moneyForPurchase) {
try {
Integer.parseInt(moneyForPurchase);
} catch (NumberFormatException e) {
- throw new IllegalStateException(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ throw new IllegalArgumentException(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
}
private static void checkRightCommaFormat(String winningNumbers) {
if (winningNumbers.startsWith(",")) {
- throw new IllegalStateException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
}
if (winningNumbers.endsWith(",")) {
- throw new IllegalStateException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
}
if (winningNumbers.contains(",,")) {
- throw new IllegalStateException(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
}
}
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
index ec199f1..0129e80 100644
--- a/src/test/java/lotto/view/InputViewTest.java
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -26,19 +26,12 @@ class InputViewTest {
assertThat(input).isEqualTo(String.valueOf(money));
}
- private static void setInput(String input) {
- OutputStream out = new ByteArrayOutputStream();
- System.setOut(new PrintStream(out));
- InputStream in = new ByteArrayInputStream(input.getBytes());
- System.setIn(in);
- }
-
@Test
- void ๊ตฌ์
๊ธ์ก_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+ void ๊ตฌ์
๊ธ์ก_๋น์ ์_์
๋ ฅ_๋ฌธ์_์์ธ๋ฐ์() {
String input = "english";
setInput(input);
assertThatThrownBy(() -> InputView.moneyForPurchaseInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
@@ -51,11 +44,11 @@ private static void setInput(String input) {
}
@Test
- void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์_์์ธ๋ฐ์() {
String input = "1,a,3,4,5,6";
setInput(input);
assertThatThrownBy(() -> InputView.winningNumbersInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
@@ -69,26 +62,26 @@ private static void setInput(String input) {
// }
@Test
- void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ์ค๋ณต() {
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ์ค๋ณต_์์ธ๋ฐ์() {
String input = "1,,3,4,5,6";
setInput(input);
assertThatThrownBy(() -> InputView.winningNumbersInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
}
@Test
- void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ฒ์_๋๋_๋์_์ผํ() {
+ void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ฒ์_๋๋_๋์_์ผํ_์์ธ๋ฐ์() {
String input = ",3,4,5,6";
setInput(input);
assertThatThrownBy(() -> InputView.winningNumbersInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
input = "3,4,5,6,";
setInput(input);
assertThatThrownBy(() -> InputView.winningNumbersInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
}
@@ -101,13 +94,19 @@ private static void setInput(String input) {
}
@Test
- void ๋ณด๋์ค๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์() {
+ void ๋ณด๋์ค๋ฒํธ_๋น์ ์_์
๋ ฅ_๋ฌธ์_์์ธ๋ฐ์() {
String input = "e";
setInput(input);
assertThatThrownBy(() -> InputView.bonusNumberInput())
- .isInstanceOf(IllegalStateException.class)
+ .isInstanceOf(IllegalArgumentException.class)
.hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
+ private static void setInput(String input) {
+ OutputStream out = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(out));
+ InputStream in = new ByteArrayInputStream(input.getBytes());
+ System.setIn(in);
+ }
}
\ No newline at end of file
From 7b7f22a0687a528a5b7a3ce30778a364e862e533 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 13:14:32 +0900
Subject: [PATCH 18/47] =?UTF-8?q?Feat(Lottos)=20:=20Lottos=20=EC=83=9D?=
=?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20validation=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/model/domain/Lottos.java | 46 ++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 src/main/java/lotto/model/domain/Lottos.java
diff --git a/src/main/java/lotto/model/domain/Lottos.java b/src/main/java/lotto/model/domain/Lottos.java
new file mode 100644
index 0000000..0e8e47f
--- /dev/null
+++ b/src/main/java/lotto/model/domain/Lottos.java
@@ -0,0 +1,46 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.LOTTOS_COUNT_OUT_OF_RANGE_100;
+import static lotto.validation.ErrorMessage.LOTTOS_SIZE_NOT_MATCH_COUNT;
+
+import java.util.List;
+
+public class Lottos {
+ private final int count;
+ private final List lottos;
+
+ public Lottos(int count, List lottos) {
+ validationCount(count);
+ this.count = count;
+ validationLottos(count, lottos);
+ this.lottos = lottos;
+ }
+
+ private void validationCount(int count) {
+ checkCountUnder100(count);
+ }
+
+ private void checkCountUnder100(int count) {
+ if (count > 100) {
+ throw new IllegalArgumentException(LOTTOS_COUNT_OUT_OF_RANGE_100.getMessage());
+ }
+ }
+
+ private void validationLottos(int count, List lottos) {
+ checkLottosSizeSameCount(count, lottos);
+ }
+
+ private static void checkLottosSizeSameCount(int count, List lottos) {
+ if (lottos.size() != count) {
+ throw new IllegalArgumentException(LOTTOS_SIZE_NOT_MATCH_COUNT.getMessage());
+ }
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public List getLottos() {
+ return lottos;
+ }
+}
From b40e679e35b5bc11765dfda5315d32574ca3b02f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 13:14:55 +0900
Subject: [PATCH 19/47] =?UTF-8?q?Test(LottosTest)=20:=20Lottos=20=ED=85=8C?=
=?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/lotto/model/domain/LottosTest.java | 76 +++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 src/test/java/lotto/model/domain/LottosTest.java
diff --git a/src/test/java/lotto/model/domain/LottosTest.java b/src/test/java/lotto/model/domain/LottosTest.java
new file mode 100644
index 0000000..55fece2
--- /dev/null
+++ b/src/test/java/lotto/model/domain/LottosTest.java
@@ -0,0 +1,76 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.LOTTOS_COUNT_OUT_OF_RANGE_100;
+import static lotto.validation.ErrorMessage.LOTTOS_SIZE_NOT_MATCH_COUNT;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class LottosTest {
+
+ private static final int TEST_RIGHT_COUNT = 2;
+ private static final int TEST_WRONG_COUNT = 101;
+ private static final List RIGHT_LOTTOS = new ArrayList<>();
+ private static final List WRING_SIZE_LOTTOS = new ArrayList<>();
+
+ @BeforeAll
+ static void set() {
+ RIGHT_LOTTOS.add(new Lotto(
+ List.of(1, 2, 3, 4, 5, 6)
+ ));
+ RIGHT_LOTTOS.add(new Lotto(
+ List.of(6, 7, 8, 9, 10, 11)
+ ));
+
+ WRING_SIZE_LOTTOS.add(new Lotto(
+ List.of(1, 2, 3, 4, 5, 6)
+ ));
+ WRING_SIZE_LOTTOS.add(new Lotto(
+ List.of(6, 7, 8, 9, 10, 11)
+ ));
+ WRING_SIZE_LOTTOS.add(new Lotto(
+ List.of(10, 11, 12, 13, 14, 15)
+ ));
+ }
+
+ @AfterAll
+ static void clear() {
+ RIGHT_LOTTOS.clear();
+ WRING_SIZE_LOTTOS.clear();
+ }
+
+ @Test
+ void Lottos์_count_์ ์() {
+
+ new Lottos(
+ TEST_RIGHT_COUNT,
+ RIGHT_LOTTOS
+ );
+ }
+
+ @Test
+ void count_100_์ด๊ณผ_์์ธ๋ฐ์() {
+ Assertions.assertThatThrownBy(() ->
+ new Lottos(
+ TEST_WRONG_COUNT,
+ RIGHT_LOTTOS
+ ))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTOS_COUNT_OUT_OF_RANGE_100.getMessage());
+ }
+
+ @Test
+ void count์_Lottos_ํฌ๊ธฐ_๋ถ์ผ์น_์์ธ๋ฐ์() {
+ Assertions.assertThatThrownBy(() ->
+ new Lottos(
+ TEST_RIGHT_COUNT,
+ WRING_SIZE_LOTTOS
+ ))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTOS_SIZE_NOT_MATCH_COUNT.getMessage());
+ }
+}
\ No newline at end of file
From 637a55b4757a3295ffee43c474824c669c5dab2b Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 13:16:52 +0900
Subject: [PATCH 20/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20Lottos=20?=
=?UTF-8?q?=EC=97=90=EB=9F=AC=EB=A9=94=EC=84=B8=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/java/lotto/validation/ErrorMessage.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 13572cb..3f94c14 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -2,9 +2,17 @@
public enum ErrorMessage {
MONEY_FOR_PURCHASE_NOT_NUMBER("๊ตฌ๋งค๊ธ์ก์ ์ซ์๋ก ์
๋ ฅํด์ฃผ์ธ์"),
+
WINNINGNUMBERS_NOT_START_WITH_COMMA("์ผํ๋ก ์์ํ ์ ์์ต๋๋ค."),
WINNINGNUMBERS_NOT_END_WITH_COMMA("์ผํ๋ก ๋๋ ์ ์์ต๋๋ค."),
- WINNINGNUMBERS_NOT_DOUBLE_COMMA("์ผํ ์ฌ์ด์ ์ซ์๋ฅผ ๋ฃ์ด์ฃผ์ธ์");
+ WINNINGNUMBERS_NOT_DOUBLE_COMMA("์ผํ ์ฌ์ด์ ์ซ์๋ฅผ ๋ฃ์ด์ฃผ์ธ์"),
+
+ LOTTO_SIZE_NOT_SIX("๋ก๋ ๋ฒํธ ๊ฐ์๋ 6๊ฐ์
๋๋ค."),
+ LOTTO_NUMBER_OUT_OF_RANGE("๋ก๋ ๋ฒํธ๋ 1~45 ์ฌ์ด์ ์์
๋๋ค."),
+ LOTTO_HAS_DUPLICATED_NUMBER("์ค๋ณต๋ ์ซ์๋ ๊ธฐ์
ํ ์ ์์ต๋๋ค."),
+
+ LOTTOS_COUNT_OUT_OF_RANGE_100("๋ก๋๋ 1ํ๋น 100๊ฐ๊น์ง ๊ตฌ๋งค๊ฐ๋ฅํฉ๋๋ค."),
+ LOTTOS_SIZE_NOT_MATCH_COUNT("๊ตฌ๋งค ๊ฐ๊ฒฉ๋งํผ ๋ก๋๋ฅผ ๊ตฌ๋งคํ์
์ผํฉ๋๋ค.");
private final String message;
From 732ee710d8b7c496ce613dd07f0b50813c3f4a09 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 14:23:38 +0900
Subject: [PATCH 21/47] =?UTF-8?q?Test(LottoTest)=20:=20=EB=A9=94=EC=84=9C?=
=?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/test/java/lotto/model/domain/LottoTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/lotto/model/domain/LottoTest.java b/src/test/java/lotto/model/domain/LottoTest.java
index 9117a7e..08304f4 100644
--- a/src/test/java/lotto/model/domain/LottoTest.java
+++ b/src/test/java/lotto/model/domain/LottoTest.java
@@ -42,7 +42,7 @@ void createLottoByDuplicatedNumber() {
}
@Test
- void ๋ก๋๋ฒํธ_๋น์ ์_๋ก๋์_๋ฒ์์ด๊ณผ_์์ธ๋ฐ์() {
+ void ๋ก๋๋ฒํธ_๋น์ ์_๋ก๋์_๋ฒ์๋ฐ_์ซ์_์์ธ๋ฐ์() {
assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 46)))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
From 069c6ed1a9c5cfba7fefeb1f0bf006a3470a960b Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 14:24:18 +0900
Subject: [PATCH 22/47] =?UTF-8?q?Feat(WinningNumbers)=20:=20=EB=8B=B9?=
=?UTF-8?q?=EC=B2=A8=EB=B2=88=ED=98=B8=EC=99=80=20=EB=B3=B4=EB=84=88?=
=?UTF-8?q?=EC=8A=A4=EB=B2=88=ED=98=B8=EB=A5=BC=20=ED=8F=AC=ED=95=A8?=
=?UTF-8?q?=ED=95=9C=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
---
.../lotto/model/domain/WinningNumbers.java | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 src/main/java/lotto/model/domain/WinningNumbers.java
diff --git a/src/main/java/lotto/model/domain/WinningNumbers.java b/src/main/java/lotto/model/domain/WinningNumbers.java
new file mode 100644
index 0000000..711e961
--- /dev/null
+++ b/src/main/java/lotto/model/domain/WinningNumbers.java
@@ -0,0 +1,51 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_IS_DUPLICATED;
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_OUT_OF_RANGE;
+
+import java.util.List;
+
+public class WinningNumbers {
+
+ private static final int MIN_LOTTO_NUMBER = 1;
+ private static final int MAX_LOTTO_NUMBER = 45;
+
+
+ private final Lotto winningLotto;
+ private final int bonusNumber;
+
+ public WinningNumbers(List winningLotto, int bonusNumber) {
+ this.winningLotto = new Lotto(winningLotto);
+ validationBonusNumber(winningLotto, bonusNumber);
+ this.bonusNumber = bonusNumber;
+ }
+
+ public void validationBonusNumber(List winningLotto, int bonusNumber) {
+ checkNumberOutOfRange(bonusNumber);
+ checkDuplicatedBonusNumber(winningLotto, bonusNumber);
+ }
+
+ private void checkDuplicatedBonusNumber(List winningLotto, int bonusNumber) {
+ if (winningLotto.contains(bonusNumber)) {
+ throw new IllegalArgumentException(BONUS_NUMBER_IS_DUPLICATED.getMessage());
+ }
+ }
+
+ private void checkNumberOutOfRange(int bonusNumber) {
+ if (isNumberOutOfRange(bonusNumber)) {
+ throw new IllegalArgumentException(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+ }
+
+ private boolean isNumberOutOfRange(int number) {
+ return number < MIN_LOTTO_NUMBER || number > MAX_LOTTO_NUMBER;
+ }
+
+ public Lotto getWinningLotto() {
+ return winningLotto;
+ }
+
+ public int getBonusNumber() {
+ return bonusNumber;
+ }
+}
From bf567b01844062a0e70798966f1a3559f7a5bc94 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 14:24:52 +0900
Subject: [PATCH 23/47] =?UTF-8?q?Test(WinningNumbersTest)=20:=20WinningNum?=
=?UTF-8?q?bers=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../model/domain/WinningNumbersTest.java | 88 +++++++++++++++++++
1 file changed, 88 insertions(+)
create mode 100644 src/test/java/lotto/model/domain/WinningNumbersTest.java
diff --git a/src/test/java/lotto/model/domain/WinningNumbersTest.java b/src/test/java/lotto/model/domain/WinningNumbersTest.java
new file mode 100644
index 0000000..8fd61a3
--- /dev/null
+++ b/src/test/java/lotto/model/domain/WinningNumbersTest.java
@@ -0,0 +1,88 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_IS_DUPLICATED;
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTO_HAS_DUPLICATED_NUMBER;
+import static lotto.validation.ErrorMessage.LOTTO_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTO_SIZE_NOT_SIX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+class WinningNumbersTest {
+ private static final List RIGHT_WINNINGNUMBERS = List.of(1, 2, 3, 4, 5, 6);
+
+ @Test
+ void winningLotto_๋ก๋๋ฒํธ_๊ฐ์_6๊ฐ๊ฐ_์๋๋ฉด_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, 6, 7), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_SIZE_NOT_SIX.getMessage());
+
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_SIZE_NOT_SIX.getMessage());
+ }
+
+ @Test
+ void winningLotto_๋ก๋๋ฒํธ_์ค๋ณต์ซ์_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, 5), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_HAS_DUPLICATED_NUMBER.getMessage());
+ }
+
+ @Test
+ void winningLotto_๋ก๋๋ฒํธ_๋ฒ์๋ฐ_์ซ์_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, 46), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, 0), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, -1), 10))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+
+ @Test
+ void bonusNumber_winningLotto์_์ค๋ณต_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new WinningNumbers(RIGHT_WINNINGNUMBERS, 5))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(BONUS_NUMBER_IS_DUPLICATED.getMessage());
+ }
+
+ @Test
+ void bonusNumber_๋ก๋๋ฒํธ_๋ฒ์๋ฐ_์ซ์_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new WinningNumbers(RIGHT_WINNINGNUMBERS, 46))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
+
+ assertThatThrownBy(() -> new WinningNumbers(RIGHT_WINNINGNUMBERS, 0))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
+
+ assertThatThrownBy(() -> new WinningNumbers(RIGHT_WINNINGNUMBERS, -1))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+
+ @Test
+ void winningLotto_bonusNumber_๋ชจ๋์ ์() {
+ int rightBonusNumber = 10;
+ WinningNumbers winningNumbers = new WinningNumbers(RIGHT_WINNINGNUMBERS, rightBonusNumber);
+
+ assertThat(winningNumbers.getWinningLotto().getNumbers()).isEqualTo(RIGHT_WINNINGNUMBERS);
+ assertThat(winningNumbers.getBonusNumber()).isEqualTo(rightBonusNumber);
+ }
+
+ @Test
+ void winningLotto_๊ฒ์ฆ์ฐ์ _bonusNumber_ํ์์() {
+ assertThatThrownBy(() -> new WinningNumbers(List.of(1, 2, 3, 4, 5, 46), -1))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+
+}
\ No newline at end of file
From d7898a44176b338d1410a4cb7abaea0c75fe4529 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 14:25:18 +0900
Subject: [PATCH 24/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20WinningNumbers?=
=?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8=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/java/lotto/validation/ErrorMessage.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 3f94c14..0982c76 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -12,7 +12,10 @@ public enum ErrorMessage {
LOTTO_HAS_DUPLICATED_NUMBER("์ค๋ณต๋ ์ซ์๋ ๊ธฐ์
ํ ์ ์์ต๋๋ค."),
LOTTOS_COUNT_OUT_OF_RANGE_100("๋ก๋๋ 1ํ๋น 100๊ฐ๊น์ง ๊ตฌ๋งค๊ฐ๋ฅํฉ๋๋ค."),
- LOTTOS_SIZE_NOT_MATCH_COUNT("๊ตฌ๋งค ๊ฐ๊ฒฉ๋งํผ ๋ก๋๋ฅผ ๊ตฌ๋งคํ์
์ผํฉ๋๋ค.");
+ LOTTOS_SIZE_NOT_MATCH_COUNT("๊ตฌ๋งค ๊ฐ๊ฒฉ๋งํผ ๋ก๋๋ฅผ ๊ตฌ๋งคํ์
์ผํฉ๋๋ค."),
+
+ BONUS_NUMBER_IS_DUPLICATED("๋น์ฒจ๋ฒํธ์ ์ค๋ณต๋ ์์
๋๋ค."),
+ BONUS_NUMBER_OUT_OF_RANGE("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋ ๋ฒํธ์ ๊ฐ์ด 1~45 ์ฌ์ด์ ์์
๋๋ค.");
private final String message;
From bca3179dd9115aa2ed32a07e16dd44c1f1b7546d Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 16:46:54 +0900
Subject: [PATCH 25/47] =?UTF-8?q?Refactor(ErrorMessage)=20:=20[ERROR]=20?=
=?UTF-8?q?=EB=AC=B8=EA=B5=AC=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 | 4 ++--
src/main/java/lotto/validation/ErrorMessage.java | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 53b6f60..390a9e2 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -24,11 +24,11 @@ https://github.com/TEAM-ALOM/java-lotto
#### LottosWinningChecker
-- ์ญํ : `Lottos`์ ๋น์ฒจ ๊ณ์ฐ
+- ์ญํ : `Lottos`์ ๋น์ฒจ ๊ณ์ฐ ํ `LottosWinningStatus` ์์ฑ
#### LottosWinningStatus
-- ์ญํ : `WinningNumbers`,`WinningType`๋ฅผ ๋ฐํ์ผ๋ก `Lottos`์ ๋น์ณ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ์ค์ง์ ๋ฐ์ดํฐ
+- ์ญํ : `WinningNumbers`,`WinningType`๋ฅผ ๋ฐํ์ผ๋ก `Lottos`์ ๋น์ณ ๊ณ์ฐ `LottoWinningChecker` ๊ฒฐ๊ณผ๋ฅผ ๋ด์ ์ค์ง์ ๋ฐ์ดํฐ
#### WinningNumbers
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 0982c76..1ce6356 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -18,12 +18,13 @@ public enum ErrorMessage {
BONUS_NUMBER_OUT_OF_RANGE("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋ ๋ฒํธ์ ๊ฐ์ด 1~45 ์ฌ์ด์ ์์
๋๋ค.");
private final String message;
+ private static final String START_ERROR = "[ERROR] ";
ErrorMessage(String message) {
this.message = message;
}
public String getMessage() {
- return message;
+ return START_ERROR + message;
}
}
From ecdd30c74b5591bd1222363290740504b5babf2e Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 17:01:11 +0900
Subject: [PATCH 26/47] =?UTF-8?q?Feat(LottosGenerator)=20:=20=EB=A1=9C?=
=?UTF-8?q?=EB=98=90=20=EA=B5=AC=EB=A7=A4=20=EA=B8=B0=EB=8A=A5=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
๊ตฌ๋งค ๊ธ์ก์ ๋ง๊ฒ ๋ก๋๋ค์ ๊ตฌ์
ํ `LottoUser`์ ์ฝ์
---
.../lotto/model/service/LottosGenerator.java | 43 +++++++++++++++++++
1 file changed, 43 insertions(+)
create mode 100644 src/main/java/lotto/model/service/LottosGenerator.java
diff --git a/src/main/java/lotto/model/service/LottosGenerator.java b/src/main/java/lotto/model/service/LottosGenerator.java
new file mode 100644
index 0000000..e5d9be3
--- /dev/null
+++ b/src/main/java/lotto/model/service/LottosGenerator.java
@@ -0,0 +1,43 @@
+package lotto.model.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import lotto.model.domain.Lotto;
+import lotto.model.domain.LottoUser;
+import lotto.model.domain.Lottos;
+import org.kokodak.Randoms;
+
+public class LottosGenerator {
+ private static final int MIN_LOTTO_NUMBER = 1;
+ private static final int MAX_LOTTO_NUMBER = 45;
+ private static final int LOTTO_COUNT = 6;
+
+ private final LottoUser lottoUser;
+
+ public LottosGenerator(LottoUser lottoUser) {
+ this.lottoUser = lottoUser;
+ }
+
+ public void generateLottosAndInput() {
+ int count = lottoUser.getMoney() / 1000;
+
+ List userLottos = generateLottos(count);
+
+ lottoUser.setLottos(new Lottos(
+ count, userLottos
+ ));
+ }
+
+ private List generateLottos(int count) {
+ List userLottos = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ userLottos.add(generateLotto());
+ }
+ return userLottos;
+ }
+
+ private Lotto generateLotto() {
+ return new Lotto(Randoms.pickUniqueNumbersInRange(MIN_LOTTO_NUMBER, MAX_LOTTO_NUMBER, LOTTO_COUNT));
+ }
+
+}
From f1293a9106ecf6b324ac4024ca6c6d730394ec3f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Thu, 21 Mar 2024 17:01:47 +0900
Subject: [PATCH 27/47] =?UTF-8?q?Test(LottosGeneratorTest)=20:=20=EB=A1=9C?=
=?UTF-8?q?=EB=98=90=20=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=ED=85=8C?=
=?UTF-8?q?=EC=8A=A4=ED=8A=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../model/service/LottosGeneratorTest.java | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 src/test/java/lotto/model/service/LottosGeneratorTest.java
diff --git a/src/test/java/lotto/model/service/LottosGeneratorTest.java b/src/test/java/lotto/model/service/LottosGeneratorTest.java
new file mode 100644
index 0000000..abac570
--- /dev/null
+++ b/src/test/java/lotto/model/service/LottosGeneratorTest.java
@@ -0,0 +1,25 @@
+package lotto.model.service;
+
+import lotto.model.domain.LottoUser;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class LottosGeneratorTest {
+
+ private static LottoUser lottoUser;
+ private static LottosGenerator lottosGenerator;
+
+ @BeforeAll
+ static void setLottoUser() {
+ lottoUser = new LottoUser(3000);
+ lottosGenerator = new LottosGenerator(lottoUser);
+ }
+
+ @Test
+ void Lottos_์ ์_์์ฑํ_์ ์ ์_์ฝ์
() {
+ lottosGenerator.generateLottosAndInput();
+ Assertions.assertThat(lottoUser.getLottos().getLottos().size())
+ .isEqualTo(lottoUser.getMoney() / 1000);
+ }
+}
\ No newline at end of file
From 335f4274f4aa2f68450054facc5d09382ef850d6 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:11:32 +0900
Subject: [PATCH 28/47] =?UTF-8?q?Feat(LottosWinningStatus)=20:=20=EC=9C=A0?=
=?UTF-8?q?=EC=A0=80=EC=9D=98=20=EB=8B=B9=EC=B2=A8=20=EA=B2=B0=EA=B3=BC=20?=
=?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B0=9D=EC=B2=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../model/domain/LottosWinningStatus.java | 44 +++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 src/main/java/lotto/model/domain/LottosWinningStatus.java
diff --git a/src/main/java/lotto/model/domain/LottosWinningStatus.java b/src/main/java/lotto/model/domain/LottosWinningStatus.java
new file mode 100644
index 0000000..2eefc4b
--- /dev/null
+++ b/src/main/java/lotto/model/domain/LottosWinningStatus.java
@@ -0,0 +1,44 @@
+package lotto.model.domain;
+
+public class LottosWinningStatus {
+ private final int matchesThree;
+ private final int matchesFour;
+ private final int matchesFive;
+ private final int matchesFiveWithBonus;
+ private final int matchesSix;
+ private final double profitRatio;
+
+ public LottosWinningStatus(int matchesThree, int matchesFour, int matchesFive, int matchesFiveWithBonus,
+ int matchesSix, double profitRatio) {
+ this.matchesThree = matchesThree;
+ this.matchesFour = matchesFour;
+ this.matchesFive = matchesFive;
+ this.matchesFiveWithBonus = matchesFiveWithBonus;
+ this.matchesSix = matchesSix;
+ this.profitRatio = profitRatio;
+ }
+
+ public double getProfitRatio() {
+ return profitRatio;
+ }
+
+ public int getMatchesThree() {
+ return matchesThree;
+ }
+
+ public int getMatchesFour() {
+ return matchesFour;
+ }
+
+ public int getMatchesFive() {
+ return matchesFive;
+ }
+
+ public int getMatchesFiveWithBonus() {
+ return matchesFiveWithBonus;
+ }
+
+ public int getMatchesSix() {
+ return matchesSix;
+ }
+}
From 350bc3286464128a43af2fa925db347ecfe2ba0f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:12:35 +0900
Subject: [PATCH 29/47] =?UTF-8?q?Feat(LottoUser)=20:=20lottos,=20money,=20?=
=?UTF-8?q?=EB=8B=B9=EC=B2=A8=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EA=B0=80?=
=?UTF-8?q?=EC=A7=80=EA=B3=A0=EC=9E=88=EB=8A=94=20=EC=9C=A0=EC=A0=80=20?=
=?UTF-8?q?=EA=B0=9D=EC=B2=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/lotto/model/domain/LottoUser.java | 61 +++++++++++++++++++
1 file changed, 61 insertions(+)
create mode 100644 src/main/java/lotto/model/domain/LottoUser.java
diff --git a/src/main/java/lotto/model/domain/LottoUser.java b/src/main/java/lotto/model/domain/LottoUser.java
new file mode 100644
index 0000000..e357686
--- /dev/null
+++ b/src/main/java/lotto/model/domain/LottoUser.java
@@ -0,0 +1,61 @@
+package lotto.model.domain;
+
+public class LottoUser {
+ private Lottos lottos;
+ private final int money;
+ private LottosWinningStatus lottosWinningStatus;
+
+
+ public LottoUser(int money) {
+ this.money = money;
+ }
+
+ public LottoUser(Lottos lottos, int money) {
+ this.lottos = lottos;
+ this.money = money;
+ }
+
+ public LottoUser(Lottos lottos, int money, LottosWinningStatus lottosWinningStatus) {
+ this.lottos = lottos;
+ validationMoney(money);
+ this.money = money;
+ this.lottosWinningStatus = lottosWinningStatus;
+ }
+
+ private void validationMoney(int money) {
+ checkMoneyOutOfRange(money);
+ checkMoneyDivisibility(money);
+ }
+
+ private void checkMoneyDivisibility(int money) {
+ if (money % 1000 != 0) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ private void checkMoneyOutOfRange(int money) {
+ if (money < 0 || money > 100000) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public Lottos getLottos() {
+ return lottos;
+ }
+
+ public int getMoney() {
+ return money;
+ }
+
+ public LottosWinningStatus getLottosWinningStatus() {
+ return lottosWinningStatus;
+ }
+
+ public void setLottos(Lottos lottos) {
+ this.lottos = lottos;
+ }
+
+ public void setLottosWinningStatus(LottosWinningStatus lottosWinningStatus) {
+ this.lottosWinningStatus = lottosWinningStatus;
+ }
+}
From e8aefb4ba6a697a515248566b58056d97bcef970 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:13:11 +0900
Subject: [PATCH 30/47] =?UTF-8?q?Feat(WinningType)=20:=20=EB=8B=B9?=
=?UTF-8?q?=EC=B2=A8=EC=A2=85=EB=A5=98=20=EB=B0=8F=20=EB=8B=B9=EC=B2=A8?=
=?UTF-8?q?=EA=B8=88=EC=95=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/lotto/model/domain/WinningType.java | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 src/main/java/lotto/model/domain/WinningType.java
diff --git a/src/main/java/lotto/model/domain/WinningType.java b/src/main/java/lotto/model/domain/WinningType.java
new file mode 100644
index 0000000..d6bc206
--- /dev/null
+++ b/src/main/java/lotto/model/domain/WinningType.java
@@ -0,0 +1,26 @@
+package lotto.model.domain;
+
+public enum WinningType {
+ MATCHES_SIX("6๊ฐ ์ผ์น (2,000,000,000์)", 2_000_000_000),
+ MATCHES_FIVE_WITH_BONUS("5๊ฐ ์ผ์น, ๋ณด๋์ค ๋ณผ ์ผ์น (30,000,000์)", 30_000_000),
+ MATCHES_FIVE("5๊ฐ ์ผ์น (1,500,000์)", 1_500_000),
+ MATCHES_FOUR("4๊ฐ ์ผ์น (50,000์)", 50_000),
+ MATCHES_THREE("3๊ฐ ์ผ์น (5,000์)", 5_000),
+ NO_MATCH("๊ฝ (0์)", 0);
+
+ private final String message;
+ private final long profitMoney;
+
+ WinningType(String message, long profitMoney) {
+ this.message = message;
+ this.profitMoney = profitMoney;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public long getProfitMoney() {
+ return profitMoney;
+ }
+}
From 34e069e6c2a772b87197808b574a3f5ddd67f5e3 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:13:56 +0900
Subject: [PATCH 31/47] =?UTF-8?q?Feat(LottosWinningChecker)=20:=20?=
=?UTF-8?q?=EB=8B=B9=EC=B2=A8=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EA=B3=84?=
=?UTF-8?q?=EC=82=B0=ED=95=98=EC=97=AC=20=EB=B0=98=ED=99=98=ED=95=98?=
=?UTF-8?q?=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=ED=81=B4=EB=9E=98?=
=?UTF-8?q?=EC=8A=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../model/service/LottosWinningChecker.java | 122 ++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 src/main/java/lotto/model/service/LottosWinningChecker.java
diff --git a/src/main/java/lotto/model/service/LottosWinningChecker.java b/src/main/java/lotto/model/service/LottosWinningChecker.java
new file mode 100644
index 0000000..59d6454
--- /dev/null
+++ b/src/main/java/lotto/model/service/LottosWinningChecker.java
@@ -0,0 +1,122 @@
+package lotto.model.service;
+
+import static lotto.model.domain.WinningType.MATCHES_FIVE;
+import static lotto.model.domain.WinningType.MATCHES_FIVE_WITH_BONUS;
+import static lotto.model.domain.WinningType.MATCHES_FOUR;
+import static lotto.model.domain.WinningType.MATCHES_SIX;
+import static lotto.model.domain.WinningType.MATCHES_THREE;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import lotto.model.domain.Lotto;
+import lotto.model.domain.LottoUser;
+import lotto.model.domain.Lottos;
+import lotto.model.domain.LottosWinningStatus;
+import lotto.model.domain.WinningNumbers;
+
+public class LottosWinningChecker {
+
+ public static LottosWinningStatus generateWinningStatusAndInput(LottoUser lottoUser,
+ WinningNumbers winningNumbers) {
+ Lottos lottos = lottoUser.getLottos();
+
+ AtomicInteger matchesThree = new AtomicInteger();
+ AtomicInteger matchesFour = new AtomicInteger();
+ AtomicInteger matchesFive = new AtomicInteger();
+ AtomicInteger matchesFiveWithBonus = new AtomicInteger();
+ AtomicInteger matchesSix = new AtomicInteger();
+
+ lottos.getLottos().forEach(lotto -> {
+ int matchesCount = getMatchesCount(lotto.getNumbers(), winningNumbers.getWinningLotto().getNumbers());
+ stackByMatchesCount(lotto, matchesCount, matchesThree, matchesFour, matchesFiveWithBonus, matchesFive,
+ matchesSix, winningNumbers);
+ }
+ );
+
+ return getWinningStatus(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix, lottoUser);
+
+// inputWinningStatusToUser(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix);
+ }
+
+ private static LottosWinningStatus getWinningStatus(AtomicInteger matchesThree, AtomicInteger matchesFour,
+ AtomicInteger matchesFive,
+ AtomicInteger matchesFiveWithBonus, AtomicInteger matchesSix,
+ LottoUser lottoUser) {
+ return new LottosWinningStatus(
+ matchesThree.intValue(),
+ matchesFour.intValue(),
+ matchesFive.intValue(),
+ matchesFiveWithBonus.intValue(),
+ matchesSix.intValue(),
+
+ calculateProfitRatio(matchesThree,
+ matchesFour,
+ matchesFive,
+ matchesFiveWithBonus,
+ matchesSix, lottoUser)
+ );
+ }
+
+ private static double calculateProfitRatio(AtomicInteger matchesThree, AtomicInteger matchesFour,
+ AtomicInteger matchesFive,
+ AtomicInteger matchesFiveWithBonus, AtomicInteger matchesSix,
+ LottoUser lottoUser) {
+ return (double) getTotalProfitMoney(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix)
+ / lottoUser.getMoney();
+ }
+
+ private static long getTotalProfitMoney(AtomicInteger matchesThree, AtomicInteger matchesFour,
+ AtomicInteger matchesFive,
+ AtomicInteger matchesFiveWithBonus, AtomicInteger matchesSix) {
+ return matchesThree.intValue() * MATCHES_THREE.getProfitMoney()
+ + matchesFour.intValue() * MATCHES_FOUR.getProfitMoney()
+ + matchesFive.intValue() * MATCHES_FIVE.getProfitMoney()
+ + matchesFiveWithBonus.intValue() * MATCHES_FIVE_WITH_BONUS.getProfitMoney()
+ + matchesSix.intValue() * MATCHES_SIX.getProfitMoney();
+ }
+
+ private static void stackByMatchesCount(Lotto lotto, int matchesCount, AtomicInteger matchesThree,
+ AtomicInteger matchesFour, AtomicInteger matchesFiveWithBonus,
+ AtomicInteger matchesFive, AtomicInteger matchesSix,
+ WinningNumbers winningNumbers) {
+ switch (matchesCount) {
+ case 3:
+ matchesThree.getAndIncrement();
+ break;
+ case 4:
+ matchesFour.getAndIncrement();
+ break;
+ case 5:
+ if (isMatchToBonusNumber(lotto, winningNumbers)) {
+ matchesFiveWithBonus.getAndIncrement();
+ break;
+ }
+ matchesFive.getAndIncrement();
+ break;
+ case 6:
+ matchesSix.getAndIncrement();
+ break;
+ }
+ }
+
+ private static boolean isMatchToBonusNumber(Lotto lotto, WinningNumbers winningNumbers) {
+ return lotto.getNumbers().contains(winningNumbers.getBonusNumber());
+ }
+
+ private static int getMatchesCount(List list1, List list2) {
+ Set set1 = new HashSet<>(list1);
+ Set set2 = new HashSet<>(list2);
+
+ set1.retainAll(set2);
+
+ return set1.size();
+ }
+}
+
+//3๊ฐ ์ผ์น (5,000์) - 1๊ฐ
+//4๊ฐ ์ผ์น (50,000์) - 0๊ฐ
+//5๊ฐ ์ผ์น (1,500,000์) - 0๊ฐ
+//5๊ฐ ์ผ์น, ๋ณด๋์ค ๋ณผ ์ผ์น (30,000,000์) - 0๊ฐ
+//6๊ฐ ์ผ์น (2,000,000,000์) - 0๊ฐ
\ No newline at end of file
From 2d84842f89f2faeb328551216ff7b6e4444705dc Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:15:29 +0900
Subject: [PATCH 32/47] =?UTF-8?q?Test(LottosWinningCheckerTest)=20:=20Lott?=
=?UTF-8?q?osWinningChecker=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
---
.../service/LottosWinningCheckerTest.java | 176 ++++++++++++++++++
1 file changed, 176 insertions(+)
create mode 100644 src/test/java/lotto/model/service/LottosWinningCheckerTest.java
diff --git a/src/test/java/lotto/model/service/LottosWinningCheckerTest.java b/src/test/java/lotto/model/service/LottosWinningCheckerTest.java
new file mode 100644
index 0000000..df30f9c
--- /dev/null
+++ b/src/test/java/lotto/model/service/LottosWinningCheckerTest.java
@@ -0,0 +1,176 @@
+package lotto.model.service;
+
+import static lotto.model.domain.WinningType.MATCHES_FIVE;
+import static lotto.model.domain.WinningType.MATCHES_FIVE_WITH_BONUS;
+import static lotto.model.domain.WinningType.MATCHES_FOUR;
+import static lotto.model.domain.WinningType.MATCHES_SIX;
+import static lotto.model.domain.WinningType.MATCHES_THREE;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import lotto.model.domain.Lotto;
+import lotto.model.domain.LottoUser;
+import lotto.model.domain.Lottos;
+import lotto.model.domain.LottosWinningStatus;
+import lotto.model.domain.WinningNumbers;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class LottosWinningCheckerTest {
+ private static LottoUser lottoUser;
+ private static WinningNumbers winningNumbers;
+ private static final int USER_MONEY = 5000;
+
+ @BeforeAll
+ static void initData() {
+ List inputLottos = new ArrayList<>();
+ addLotto(inputLottos, List.of(1, 2, 3, 4, 5, 6));
+ addLotto(inputLottos, List.of(10, 11, 12, 13, 14, 15));
+ addLotto(inputLottos, List.of(35, 36, 37, 38, 39, 40));
+ addLotto(inputLottos, List.of(17, 18, 19, 20, 21, 22));
+ addLotto(inputLottos, List.of(30, 31, 32, 33, 34, 35));
+ lottoUser = new LottoUser(
+ new Lottos(
+ 5,
+ inputLottos
+ ),
+ USER_MONEY
+ );
+ }
+
+ private static void addLotto(List inputLottos, List lottoNumbers) {
+ inputLottos.add(
+ new Lotto(lottoNumbers)
+ );
+ }
+
+
+ /**
+ * ๊ฐ_๋น์ฒจ_ํ์
์_๋ง๋_๊ฐ_์ ์๋์ _ํ์ธ
+ */
+ @Test
+ void ์ ์_3๊ฐ์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(4, 5, 6, 10, 11, 12);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(inputWinningLottoNumbers,
+ bonusNumber);
+
+ assertThat(lottosWinningStatus.getMatchesThree()).isEqualTo(2);
+ }
+
+
+ @Test
+ void ์ ์_4๊ฐ์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(4, 5, 10, 11, 12, 13);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getMatchesFour()).isEqualTo(1);
+ }
+
+ @Test
+ void ์ ์_5๊ฐ์ผ์น_๋ณด๋์ค_๋ถ์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(5, 10, 11, 12, 13, 14);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getMatchesFive()).isEqualTo(1);
+ }
+
+ @Test
+ void ์ ์_5๊ฐ์ผ์น_๋ณด๋์ค๋_์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(5, 10, 11, 12, 13, 14);
+ int bonusNumber = 15;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getMatchesFiveWithBonus()).isEqualTo(1);
+ }
+
+ @Test
+ void ์ ์_6๊ฐ์ผ์น_์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(10, 11, 12, 13, 14, 15);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getMatchesSix()).isEqualTo(1);
+ }
+
+ /**
+ * ๊ฐํ์
_์์ต๋ฅ _์ ์๊ณ์ฐ
+ */
+ @Test
+ void ์์ต๋ฅ _์ ์_3๊ฐ์ผ์น_๊ณ์ฐ() {
+ List inputWinningLottoNumbers = List.of(4, 5, 6, 10, 11, 12);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(inputWinningLottoNumbers,
+ bonusNumber);
+
+ assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
+ (double) lottosWinningStatus.getMatchesThree() * MATCHES_THREE.getProfitMoney() / USER_MONEY);
+ }
+
+ @Test
+ void ์์ต๋ฅ _์ ์_4๊ฐ์ผ์น_๊ณ์ฐ() {
+ List inputWinningLottoNumbers = List.of(1, 2, 3, 4, 41, 42);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ System.out.println(lottosWinningStatus.getMatchesThree());
+ System.out.println(lottosWinningStatus.getMatchesFour());
+ System.out.println(lottosWinningStatus.getMatchesFive());
+
+ assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
+ (double) lottosWinningStatus.getMatchesFour() * MATCHES_FOUR.getProfitMoney() / USER_MONEY);
+ }
+
+ @Test
+ void ์์ต๋ฅ _์ ์_5๊ฐ์ผ์น_๋ณด๋์ค_๋ถ์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(5, 10, 11, 12, 13, 14);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
+ (double) lottosWinningStatus.getMatchesFive() * MATCHES_FIVE.getProfitMoney() / USER_MONEY);
+ }
+
+ @Test
+ void ์์ต๋ฅ _์ ์_5๊ฐ์ผ์น_๋ณด๋์ค๋_์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(5, 10, 11, 12, 13, 14);
+ int bonusNumber = 15;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
+ (double) lottosWinningStatus.getMatchesFiveWithBonus() *
+ MATCHES_FIVE_WITH_BONUS.getProfitMoney() / USER_MONEY);
+ }
+
+ @Test
+ void ์์ต๋ฅ _์ ์_6๊ฐ์ผ์น_์ผ์น_ํ์ธ() {
+ List inputWinningLottoNumbers = List.of(10, 11, 12, 13, 14, 15);
+ int bonusNumber = 45;
+ LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
+ inputWinningLottoNumbers, bonusNumber);
+
+ assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
+ (double) lottosWinningStatus.getMatchesSix() * MATCHES_SIX.getProfitMoney() / USER_MONEY);
+ }
+
+ private static LottosWinningStatus getLottosWinningStatusAfterWinningChecker(List inputWinningLottoNumbers,
+ int bonusNumber) {
+ winningNumbers = new WinningNumbers(
+ inputWinningLottoNumbers,
+ bonusNumber
+ );
+ return LottosWinningChecker.generateWinningStatusAndInput(lottoUser,
+ winningNumbers);
+ }
+
+}
\ No newline at end of file
From 31b5a5b42ae95bf1e16f993f632308630db5101f Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:59:16 +0900
Subject: [PATCH 33/47] =?UTF-8?q?Refactor(LottosWinningStatus)=20:=20profi?=
=?UTF-8?q?tRatio=EC=97=90=20=EB=8C=80=ED=95=9C=20validation=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
---
.../lotto/model/domain/LottosWinningStatus.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/main/java/lotto/model/domain/LottosWinningStatus.java b/src/main/java/lotto/model/domain/LottosWinningStatus.java
index 2eefc4b..dbf04e8 100644
--- a/src/main/java/lotto/model/domain/LottosWinningStatus.java
+++ b/src/main/java/lotto/model/domain/LottosWinningStatus.java
@@ -1,5 +1,7 @@
package lotto.model.domain;
+import lotto.validation.ErrorMessage;
+
public class LottosWinningStatus {
private final int matchesThree;
private final int matchesFour;
@@ -15,9 +17,20 @@ public LottosWinningStatus(int matchesThree, int matchesFour, int matchesFive, i
this.matchesFive = matchesFive;
this.matchesFiveWithBonus = matchesFiveWithBonus;
this.matchesSix = matchesSix;
+ validationProfitRatio(profitRatio);
this.profitRatio = profitRatio;
}
+ private void validationProfitRatio(double profitRatio) {
+ checkMaxProfitRatio(profitRatio);
+ }
+
+ private static void checkMaxProfitRatio(double profitRatio) {
+ if (profitRatio > (double) WinningType.MATCHES_SIX.getProfitMoney() / 1000) {
+ throw new IllegalArgumentException(ErrorMessage.WINNING_STATUS_PROFIT_RATIO_OVER_MAX.getMessage());
+ }
+ }
+
public double getProfitRatio() {
return profitRatio;
}
From 77ee38c8a57a14aa3bba0cbefca32012cb779b60 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 20:59:51 +0900
Subject: [PATCH 34/47] =?UTF-8?q?Test(LottosWinningStatusTest)=20:=20`Lott?=
=?UTF-8?q?osWinningStatus`=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
---
.../model/domain/LottosWinningStatusTest.java | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 src/test/java/lotto/model/domain/LottosWinningStatusTest.java
diff --git a/src/test/java/lotto/model/domain/LottosWinningStatusTest.java b/src/test/java/lotto/model/domain/LottosWinningStatusTest.java
new file mode 100644
index 0000000..050e84c
--- /dev/null
+++ b/src/test/java/lotto/model/domain/LottosWinningStatusTest.java
@@ -0,0 +1,20 @@
+package lotto.model.domain;
+
+import static lotto.validation.ErrorMessage.WINNING_STATUS_PROFIT_RATIO_OVER_MAX;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.jupiter.api.Test;
+
+class LottosWinningStatusTest {
+
+ private static final double MAX_PROFIT_RATIO_PLUS_ONE =
+ (double) (WinningType.MATCHES_SIX.getProfitMoney() + 1) / 1000;
+
+ @Test
+ void ์ต๋์์ต๋ฅ ์_์ด๊ณผ์์ต๋ฅ ์ด๋ฉด_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> new LottosWinningStatus(
+ 1, 1, 1, 1, 1, MAX_PROFIT_RATIO_PLUS_ONE
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(WINNING_STATUS_PROFIT_RATIO_OVER_MAX.getMessage());
+ }
+}
\ No newline at end of file
From a555419a7b427cc5a9cfebd07d3cdae3c0843097 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Sun, 24 Mar 2024 21:00:21 +0900
Subject: [PATCH 35/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20WinningStatus=20?=
=?UTF-8?q?validation=EC=97=90=20=EB=8C=80=ED=95=9C=20=EB=A9=94=EC=84=B8?=
=?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/validation/ErrorMessage.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 1ce6356..28f06e6 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -15,7 +15,9 @@ public enum ErrorMessage {
LOTTOS_SIZE_NOT_MATCH_COUNT("๊ตฌ๋งค ๊ฐ๊ฒฉ๋งํผ ๋ก๋๋ฅผ ๊ตฌ๋งคํ์
์ผํฉ๋๋ค."),
BONUS_NUMBER_IS_DUPLICATED("๋น์ฒจ๋ฒํธ์ ์ค๋ณต๋ ์์
๋๋ค."),
- BONUS_NUMBER_OUT_OF_RANGE("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋ ๋ฒํธ์ ๊ฐ์ด 1~45 ์ฌ์ด์ ์์
๋๋ค.");
+ BONUS_NUMBER_OUT_OF_RANGE("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋ ๋ฒํธ์ ๊ฐ์ด 1~45 ์ฌ์ด์ ์์
๋๋ค."),
+
+ WINNING_STATUS_PROFIT_RATIO_OVER_MAX("์์ต๋ฅ ์ ์ด๋ก ์ ์ต๋ ์์ต๋ฅ ์ ๋์ ์ ์์ต๋๋ค. ๋ค์ ๊ณ์ฐํ์ธ์");
private final String message;
private static final String START_ERROR = "[ERROR] ";
From 28a9df47e8311568b96de90f6a0fa98a74086718 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:52:10 +0900
Subject: [PATCH 36/47] =?UTF-8?q?Feat(OutputView)=20:=20=EC=B6=9C=EB=A0=A5?=
=?UTF-8?q?=20=EC=97=AD=ED=95=A0=20=ED=81=B4=EB=9E=98=EC=8A=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/OutputView.java | 79 ++++++++++++++++++++++++
1 file changed, 79 insertions(+)
create mode 100644 src/main/java/lotto/view/OutputView.java
diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java
new file mode 100644
index 0000000..2987d9d
--- /dev/null
+++ b/src/main/java/lotto/view/OutputView.java
@@ -0,0 +1,79 @@
+package lotto.view;
+
+import static lotto.validation.ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS;
+import static lotto.view.ViewMessage.BONUS_NUMBER_PROMPT;
+import static lotto.view.ViewMessage.LOTTOS_SIZE_PROMPT;
+import static lotto.view.ViewMessage.MAIN_WINNING_NUMBERS_PROMPT;
+import static lotto.view.ViewMessage.PURCHASE_AMOUNT_PROMPT;
+import static lotto.view.ViewMessage.WINNING_STATUS_MAIN;
+import static lotto.view.ViewMessage.WINNING_STATUS_START;
+
+import java.util.List;
+import lotto.model.domain.Lotto;
+import lotto.model.domain.LottosWinningStatus;
+
+public class OutputView {
+
+ public static void moneyForPurchaseInputMessage() {
+ System.out.println(PURCHASE_AMOUNT_PROMPT.getMessage());
+ }
+
+ public static void userLottos(List userLottos) {
+ StringBuilder stringBuilder = new StringBuilder();
+ System.out.printf(LOTTOS_SIZE_PROMPT.getMessage(), userLottos.size());
+ for (Lotto userLotto : userLottos) {
+ stringBuilder.append(userLotto.getNumbers().toString()).append("\n");
+ }
+ System.out.println(stringBuilder);
+ }
+
+ public static void winningNumbersInputMessage() {
+ System.out.println(MAIN_WINNING_NUMBERS_PROMPT.getMessage());
+ }
+
+ public static void bonusNumberInputMessage() {
+ System.out.println(BONUS_NUMBER_PROMPT.getMessage());
+ }
+
+ public static void winningStatusMessage(LottosWinningStatus lottosWinningStatus) {
+ validationWinningStatusNumber(lottosWinningStatus);
+ System.out.println(WINNING_STATUS_START.getMessage());
+ System.out.printf(WINNING_STATUS_MAIN.getMessage(),
+ lottosWinningStatus.getMatchesThree(),
+ lottosWinningStatus.getMatchesFour(),
+ lottosWinningStatus.getMatchesFive(),
+ lottosWinningStatus.getMatchesFiveWithBonus(),
+ lottosWinningStatus.getMatchesSix(),
+ lottosWinningStatus.getProfitRatio());
+ }
+
+ public static void displayErrorMessage(String errorMessage) {
+ System.out.println(errorMessage);
+ }
+
+ private static void validationWinningStatusNumber(LottosWinningStatus lottosWinningStatus) {
+ checkStatusValueMinus(lottosWinningStatus.getMatchesThree());
+ checkStatusValueMinus(lottosWinningStatus.getMatchesFour());
+ checkStatusValueMinus(lottosWinningStatus.getMatchesFive());
+ checkStatusValueMinus(lottosWinningStatus.getMatchesFiveWithBonus());
+ checkStatusValueMinus(lottosWinningStatus.getMatchesSix());
+ checkStatusValueMinus(roundToTwoDigits(lottosWinningStatus.getProfitRatio()));
+ }
+
+ private static double roundToTwoDigits(double profitRatio) {
+ return profitRatio + 0.05;
+ }
+
+ private static void checkStatusValueMinus(int lottosWinningStatusValue) {
+ if (lottosWinningStatusValue < 0) {
+ throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+ }
+ }
+
+ private static void checkStatusValueMinus(double lottosWinningStatusValue) {
+ if (lottosWinningStatusValue < 0) {
+ throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+ }
+ }
+
+}
\ No newline at end of file
From 983aea980f5fe826cb1db679242daab0ea2cd8e7 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:52:32 +0900
Subject: [PATCH 37/47] =?UTF-8?q?Feat(ViewMessage)=20:=20=ED=99=94?=
=?UTF-8?q?=EB=A9=B4=EC=97=90=20=ED=91=9C=EC=8B=9C=EB=90=A0=20=EB=AC=B8?=
=?UTF-8?q?=EA=B5=AC=EB=93=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/view/ViewMessage.java | 33 +++++++++++++++++++++++
1 file changed, 33 insertions(+)
create mode 100644 src/main/java/lotto/view/ViewMessage.java
diff --git a/src/main/java/lotto/view/ViewMessage.java b/src/main/java/lotto/view/ViewMessage.java
new file mode 100644
index 0000000..46a4e77
--- /dev/null
+++ b/src/main/java/lotto/view/ViewMessage.java
@@ -0,0 +1,33 @@
+package lotto.view;
+
+import static lotto.model.domain.WinningType.MATCHES_FIVE;
+import static lotto.model.domain.WinningType.MATCHES_FIVE_WITH_BONUS;
+import static lotto.model.domain.WinningType.MATCHES_FOUR;
+import static lotto.model.domain.WinningType.MATCHES_SIX;
+import static lotto.model.domain.WinningType.MATCHES_THREE;
+
+public enum ViewMessage {
+ PURCHASE_AMOUNT_PROMPT("๊ตฌ์
๊ธ์ก์ ์
๋ ฅํด ์ฃผ์ธ์.\n"),
+ MAIN_WINNING_NUMBERS_PROMPT("๋น์ฒจ ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.\n"),
+ BONUS_NUMBER_PROMPT("๋ณด๋์ค ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.\n"),
+ LOTTOS_SIZE_PROMPT("%d๊ฐ๋ฅผ ๊ตฌ๋งคํ์ต๋๋ค.\n"),
+ WINNING_STATUS_START("๋น์ฒจ ํต๊ณ\n---"),
+ WINNING_STATUS_MAIN(
+ MATCHES_THREE.getMessage() + " - %d๊ฐ\n"
+ + MATCHES_FOUR.getMessage() + " - %d๊ฐ\n"
+ + MATCHES_FIVE.getMessage() + " - %d๊ฐ\n"
+ + MATCHES_FIVE_WITH_BONUS.getMessage() + " - %d๊ฐ\n"
+ + MATCHES_SIX.getMessage() + " - %d๊ฐ\n"
+ + "์ด ์์ต๋ฅ ์ %.1f%%์
๋๋ค."
+ );
+
+ private final String message;
+
+ ViewMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
From 951d99ddd38009fd8246c77d6f9e6716da1e6505 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:52:54 +0900
Subject: [PATCH 38/47] =?UTF-8?q?Test(OutputViewTest)=20:=20=ED=99=94?=
=?UTF-8?q?=EB=A9=B4=20=EC=B6=9C=EB=A0=A5=20=ED=98=95=EC=8B=9D=20=ED=85=8C?=
=?UTF-8?q?=EC=8A=A4=ED=8A=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/test/java/lotto/view/OutputViewTest.java | 107 +++++++++++++++++++
1 file changed, 107 insertions(+)
create mode 100644 src/test/java/lotto/view/OutputViewTest.java
diff --git a/src/test/java/lotto/view/OutputViewTest.java b/src/test/java/lotto/view/OutputViewTest.java
new file mode 100644
index 0000000..2a0bebc
--- /dev/null
+++ b/src/test/java/lotto/view/OutputViewTest.java
@@ -0,0 +1,107 @@
+package lotto.view;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import lotto.model.domain.LottosWinningStatus;
+import lotto.validation.ErrorMessage;
+import org.junit.jupiter.api.Test;
+
+class OutputViewTest {
+ @Test
+ void ๋น์ฒจํต๊ณ_์ ์_์ถ๋ ฅ_๊ฐฏ์_0์ด์_์ ์() {
+ OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, 1, 1, 300.1222
+ )
+ );
+ }
+
+ @Test
+ void ๋น์ฒจํต๊ณ_์ ์_์ถ๋ ฅ_๊ฐฏ์_์์๋ฉด_์์ธ๋ฐ์() {
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ -1, 1, 1, 1, 1, 300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, -1, 1, 1, 1, 300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, -1, 1, 1, 300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, -1, 1, 300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, 1, -1, 300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ assertThatThrownBy(() -> OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, 1, 1, -300.1222
+ )
+ )).isInstanceOf(IllegalArgumentException.class)
+ .hasMessage(ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+
+ }
+
+ @Test
+ void ์์ต๋ฅ _๋ฐ์ฌ๋ฆผ_์ ์_ํ์ธ() {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PrintStream originalOut = System.out;
+ System.setOut(new PrintStream(outputStream));
+
+ OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, 1, 1, 300.1222
+ )
+ );
+
+ String printedOutput = outputStream.toString().trim();
+
+ System.setOut(originalOut);
+
+ assertThat(printedOutput).contains("300.1%");
+ }
+
+ @Test
+ void ์์ต๋ฅ _๋ฐ์ฌ๋ฆผ_์ ์_ํ์ธ2() {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PrintStream originalOut = System.out;
+ System.setOut(new PrintStream(outputStream));
+
+ OutputView.winningStatusMessage(
+ new LottosWinningStatus(
+ 1, 1, 1, 1, 1, 300.1722
+ )
+ );
+
+ String printedOutput = outputStream.toString().trim();
+
+ System.setOut(originalOut);
+
+ assertThat(printedOutput).contains("300.2%");
+ }
+
+
+}
\ No newline at end of file
From 73c2f98bd4edd1049536e8aa3df9a525490edb4e Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:53:19 +0900
Subject: [PATCH 39/47] =?UTF-8?q?Feat(LottoSystemController)=20:=20?=
=?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/LottoSystemController.java | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
create mode 100644 src/main/java/lotto/controller/LottoSystemController.java
diff --git a/src/main/java/lotto/controller/LottoSystemController.java b/src/main/java/lotto/controller/LottoSystemController.java
new file mode 100644
index 0000000..a5ce41c
--- /dev/null
+++ b/src/main/java/lotto/controller/LottoSystemController.java
@@ -0,0 +1,58 @@
+package lotto.controller;
+
+import java.util.List;
+import lotto.model.domain.LottoUser;
+import lotto.model.domain.WinningNumbers;
+import lotto.model.service.LottosGenerator;
+import lotto.model.service.LottosWinningChecker;
+import lotto.view.InputView;
+import lotto.view.OutputView;
+
+public class LottoSystemController {
+
+ private final LottoUser lottoUser;
+
+ public LottoSystemController(LottoUser lottoUser) {
+ this.lottoUser = lottoUser;
+ }
+
+ public void runLottoSystem() {
+ try {
+ buyLottos();
+
+ WinningNumbers winningNumbers = inputWinningNumbers();
+
+ winningResult(winningNumbers);
+ } catch (IllegalArgumentException e) {
+ OutputView.displayErrorMessage(e.getMessage());
+ }
+ }
+
+ private void buyLottos() {
+ OutputView.moneyForPurchaseInputMessage();
+ int userMoney = InputView.moneyForPurchaseInput();
+
+ lottoUser.setMoney(userMoney);
+
+ LottosGenerator.generateLottosAndInput(lottoUser, userMoney);
+
+ OutputView.userLottos(lottoUser.getLottos().getLottoBundle());
+ }
+
+ private WinningNumbers inputWinningNumbers() {
+ OutputView.winningNumbersInputMessage();
+ List winningNumbersInput = InputView.winningNumbersInput();
+
+ OutputView.bonusNumberInputMessage();
+ int bonusNumberInput = InputView.bonusNumberInput();
+
+ return new WinningNumbers(
+ winningNumbersInput, bonusNumberInput
+ );
+ }
+
+ private void winningResult(WinningNumbers winningNumbers) {
+ LottosWinningChecker.generateWinningStatusAndInput(lottoUser, winningNumbers);
+ OutputView.winningStatusMessage(lottoUser.getLottosWinningStatus());
+ }
+}
From 301f7a71bf3670ae332f936fbc3e82259fdb6f13 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:53:38 +0900
Subject: [PATCH 40/47] =?UTF-8?q?Refactor(Application)=20:=20=EC=BB=A8?=
=?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=A0=81=EC=9A=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index d190922..444453b 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,7 +1,12 @@
package lotto;
+import lotto.controller.LottoSystemController;
+import lotto.model.domain.LottoUser;
+
public class Application {
public static void main(String[] args) {
// TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ LottoSystemController lottoSystemController = new LottoSystemController(new LottoUser());
+ lottoSystemController.runLottoSystem();
}
-}
+}
\ No newline at end of file
From 0b3d0facb5b869893bd40085722c8badf05f0e8c Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:54:08 +0900
Subject: [PATCH 41/47] =?UTF-8?q?Refactor(Lottos)=20:=20lottoBundle?=
=?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/model/domain/Lottos.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/lotto/model/domain/Lottos.java b/src/main/java/lotto/model/domain/Lottos.java
index 0e8e47f..bdf3056 100644
--- a/src/main/java/lotto/model/domain/Lottos.java
+++ b/src/main/java/lotto/model/domain/Lottos.java
@@ -7,13 +7,13 @@
public class Lottos {
private final int count;
- private final List lottos;
+ private final List lottoBundle;
- public Lottos(int count, List lottos) {
+ public Lottos(int count, List lottoBundle) {
validationCount(count);
this.count = count;
- validationLottos(count, lottos);
- this.lottos = lottos;
+ validationLottos(count, lottoBundle);
+ this.lottoBundle = lottoBundle;
}
private void validationCount(int count) {
@@ -40,7 +40,7 @@ public int getCount() {
return count;
}
- public List getLottos() {
- return lottos;
+ public List getLottoBundle() {
+ return lottoBundle;
}
}
From 6b8f860592bd686b3ae66275da0c11abd525148a Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:55:02 +0900
Subject: [PATCH 42/47] =?UTF-8?q?Refactor(LottoWinningChecker)=20:=20?=
=?UTF-8?q?=EC=88=98=EC=9D=B5=EB=A5=A0=20=EA=B3=84=EC=82=B0=20=EC=98=A4?=
=?UTF-8?q?=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
---
.../model/domain/LottosWinningStatus.java | 2 +-
.../service/LottosWinningCheckerTest.java | 21 ++++++++-----------
2 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/main/java/lotto/model/domain/LottosWinningStatus.java b/src/main/java/lotto/model/domain/LottosWinningStatus.java
index dbf04e8..6529a5f 100644
--- a/src/main/java/lotto/model/domain/LottosWinningStatus.java
+++ b/src/main/java/lotto/model/domain/LottosWinningStatus.java
@@ -26,7 +26,7 @@ private void validationProfitRatio(double profitRatio) {
}
private static void checkMaxProfitRatio(double profitRatio) {
- if (profitRatio > (double) WinningType.MATCHES_SIX.getProfitMoney() / 1000) {
+ if (profitRatio > (double) WinningType.MATCHES_SIX.getProfitMoney() * 100 / 1000) {
throw new IllegalArgumentException(ErrorMessage.WINNING_STATUS_PROFIT_RATIO_OVER_MAX.getMessage());
}
}
diff --git a/src/test/java/lotto/model/service/LottosWinningCheckerTest.java b/src/test/java/lotto/model/service/LottosWinningCheckerTest.java
index df30f9c..4095211 100644
--- a/src/test/java/lotto/model/service/LottosWinningCheckerTest.java
+++ b/src/test/java/lotto/model/service/LottosWinningCheckerTest.java
@@ -19,7 +19,6 @@
class LottosWinningCheckerTest {
private static LottoUser lottoUser;
- private static WinningNumbers winningNumbers;
private static final int USER_MONEY = 5000;
@BeforeAll
@@ -111,7 +110,7 @@ private static void addLotto(List inputLottos, List lottoNumbers
bonusNumber);
assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
- (double) lottosWinningStatus.getMatchesThree() * MATCHES_THREE.getProfitMoney() / USER_MONEY);
+ (double) lottosWinningStatus.getMatchesThree() * MATCHES_THREE.getProfitMoney() * 100 / USER_MONEY);
}
@Test
@@ -121,12 +120,8 @@ private static void addLotto(List inputLottos, List lottoNumbers
LottosWinningStatus lottosWinningStatus = getLottosWinningStatusAfterWinningChecker(
inputWinningLottoNumbers, bonusNumber);
- System.out.println(lottosWinningStatus.getMatchesThree());
- System.out.println(lottosWinningStatus.getMatchesFour());
- System.out.println(lottosWinningStatus.getMatchesFive());
-
assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
- (double) lottosWinningStatus.getMatchesFour() * MATCHES_FOUR.getProfitMoney() / USER_MONEY);
+ (double) lottosWinningStatus.getMatchesFour() * MATCHES_FOUR.getProfitMoney() * 100 / USER_MONEY);
}
@Test
@@ -137,7 +132,7 @@ private static void addLotto(List inputLottos, List lottoNumbers
inputWinningLottoNumbers, bonusNumber);
assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
- (double) lottosWinningStatus.getMatchesFive() * MATCHES_FIVE.getProfitMoney() / USER_MONEY);
+ (double) lottosWinningStatus.getMatchesFive() * MATCHES_FIVE.getProfitMoney() * 100 / USER_MONEY);
}
@Test
@@ -149,7 +144,7 @@ private static void addLotto(List inputLottos, List lottoNumbers
assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
(double) lottosWinningStatus.getMatchesFiveWithBonus() *
- MATCHES_FIVE_WITH_BONUS.getProfitMoney() / USER_MONEY);
+ MATCHES_FIVE_WITH_BONUS.getProfitMoney() * 100 / USER_MONEY);
}
@Test
@@ -160,17 +155,19 @@ private static void addLotto(List inputLottos, List lottoNumbers
inputWinningLottoNumbers, bonusNumber);
assertThat(lottosWinningStatus.getProfitRatio()).isEqualTo(
- (double) lottosWinningStatus.getMatchesSix() * MATCHES_SIX.getProfitMoney() / USER_MONEY);
+ (double) lottosWinningStatus.getMatchesSix() * MATCHES_SIX.getProfitMoney() * 100 / USER_MONEY);
}
private static LottosWinningStatus getLottosWinningStatusAfterWinningChecker(List inputWinningLottoNumbers,
int bonusNumber) {
- winningNumbers = new WinningNumbers(
+ WinningNumbers winningNumbers = new WinningNumbers(
inputWinningLottoNumbers,
bonusNumber
);
- return LottosWinningChecker.generateWinningStatusAndInput(lottoUser,
+ LottosWinningChecker.generateWinningStatusAndInput(lottoUser,
winningNumbers);
+
+ return lottoUser.getLottosWinningStatus();
}
}
\ No newline at end of file
From 3e8e6ad7a6a33aba43f45a23c862f156743c16c7 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:55:32 +0900
Subject: [PATCH 43/47] =?UTF-8?q?Feat(ErrorMessage)=20:=20=EC=97=90?=
=?UTF-8?q?=EB=9F=AC=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/validation/ErrorMessage.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/validation/ErrorMessage.java b/src/main/java/lotto/validation/ErrorMessage.java
index 28f06e6..6530c9d 100644
--- a/src/main/java/lotto/validation/ErrorMessage.java
+++ b/src/main/java/lotto/validation/ErrorMessage.java
@@ -17,7 +17,9 @@ public enum ErrorMessage {
BONUS_NUMBER_IS_DUPLICATED("๋น์ฒจ๋ฒํธ์ ์ค๋ณต๋ ์์
๋๋ค."),
BONUS_NUMBER_OUT_OF_RANGE("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋ ๋ฒํธ์ ๊ฐ์ด 1~45 ์ฌ์ด์ ์์
๋๋ค."),
- WINNING_STATUS_PROFIT_RATIO_OVER_MAX("์์ต๋ฅ ์ ์ด๋ก ์ ์ต๋ ์์ต๋ฅ ์ ๋์ ์ ์์ต๋๋ค. ๋ค์ ๊ณ์ฐํ์ธ์");
+ WINNING_STATUS_PROFIT_RATIO_OVER_MAX("์์ต๋ฅ ์ ์ด๋ก ์ ์ต๋ ์์ต๋ฅ ์ ๋์ ์ ์์ต๋๋ค. ๋ค์ ๊ณ์ฐํ์ธ์"),
+
+ OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS("๋น์ฒจ ํต๊ณ์ ๊ฐ์ ์์์ผ ์ ์์ต๋๋ค.");
private final String message;
private static final String START_ERROR = "[ERROR] ";
From 27a7511e9f5950b0edb443e2fce448e1a869b153 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:56:14 +0900
Subject: [PATCH 44/47] =?UTF-8?q?Refactor(LottosGenerator)=20:=20=EB=A9=94?=
=?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B8=EC=9E=90=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../lotto/model/service/LottosGenerator.java | 19 +++++--------------
.../model/service/LottosGeneratorTest.java | 9 ++++-----
2 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/src/main/java/lotto/model/service/LottosGenerator.java b/src/main/java/lotto/model/service/LottosGenerator.java
index e5d9be3..bd90456 100644
--- a/src/main/java/lotto/model/service/LottosGenerator.java
+++ b/src/main/java/lotto/model/service/LottosGenerator.java
@@ -12,23 +12,14 @@ public class LottosGenerator {
private static final int MAX_LOTTO_NUMBER = 45;
private static final int LOTTO_COUNT = 6;
- private final LottoUser lottoUser;
- public LottosGenerator(LottoUser lottoUser) {
- this.lottoUser = lottoUser;
- }
-
- public void generateLottosAndInput() {
- int count = lottoUser.getMoney() / 1000;
-
- List userLottos = generateLottos(count);
+ public static void generateLottosAndInput(LottoUser lottoUser, int userMoney) {
+ int count = userMoney / 1000;
- lottoUser.setLottos(new Lottos(
- count, userLottos
- ));
+ lottoUser.setLottos(new Lottos(count, generateLottos(count)));
}
- private List generateLottos(int count) {
+ private static List generateLottos(int count) {
List userLottos = new ArrayList<>();
for (int i = 0; i < count; i++) {
userLottos.add(generateLotto());
@@ -36,7 +27,7 @@ private List generateLottos(int count) {
return userLottos;
}
- private Lotto generateLotto() {
+ private static Lotto generateLotto() {
return new Lotto(Randoms.pickUniqueNumbersInRange(MIN_LOTTO_NUMBER, MAX_LOTTO_NUMBER, LOTTO_COUNT));
}
diff --git a/src/test/java/lotto/model/service/LottosGeneratorTest.java b/src/test/java/lotto/model/service/LottosGeneratorTest.java
index abac570..19fdf2f 100644
--- a/src/test/java/lotto/model/service/LottosGeneratorTest.java
+++ b/src/test/java/lotto/model/service/LottosGeneratorTest.java
@@ -8,18 +8,17 @@
class LottosGeneratorTest {
private static LottoUser lottoUser;
- private static LottosGenerator lottosGenerator;
+ private static final int USER_MONEY = 3000;
@BeforeAll
static void setLottoUser() {
- lottoUser = new LottoUser(3000);
- lottosGenerator = new LottosGenerator(lottoUser);
+ lottoUser = new LottoUser(USER_MONEY);
}
@Test
void Lottos_์ ์_์์ฑํ_์ ์ ์_์ฝ์
() {
- lottosGenerator.generateLottosAndInput();
- Assertions.assertThat(lottoUser.getLottos().getLottos().size())
+ LottosGenerator.generateLottosAndInput(lottoUser, USER_MONEY);
+ Assertions.assertThat(lottoUser.getLottos().getLottoBundle().size())
.isEqualTo(lottoUser.getMoney() / 1000);
}
}
\ No newline at end of file
From 062556a3a310201e76e89b5f6bdc07b6683e5e37 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 15:56:43 +0900
Subject: [PATCH 45/47] =?UTF-8?q?Feat=20:=20=ED=95=84=EC=9A=94=EC=97=86?=
=?UTF-8?q?=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EB=B0=8F=20=EC=BD=94=EB=93=9C?=
=?UTF-8?q?=20=EC=82=AD=EC=A0=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/model/domain/LottoUser.java | 9 ++++++++-
src/main/java/lotto/model/domain/WinningType.java | 3 +--
.../lotto/model/service/LottosWinningChecker.java | 11 +++++++----
src/test/java/lotto/ApplicationTest.java | 4 ++--
src/test/java/lotto/view/InputViewTest.java | 9 ---------
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/main/java/lotto/model/domain/LottoUser.java b/src/main/java/lotto/model/domain/LottoUser.java
index e357686..4c0d1e5 100644
--- a/src/main/java/lotto/model/domain/LottoUser.java
+++ b/src/main/java/lotto/model/domain/LottoUser.java
@@ -2,9 +2,12 @@
public class LottoUser {
private Lottos lottos;
- private final int money;
+ private int money;
private LottosWinningStatus lottosWinningStatus;
+ public LottoUser() {
+
+ }
public LottoUser(int money) {
this.money = money;
@@ -58,4 +61,8 @@ public void setLottos(Lottos lottos) {
public void setLottosWinningStatus(LottosWinningStatus lottosWinningStatus) {
this.lottosWinningStatus = lottosWinningStatus;
}
+
+ public void setMoney(int money) {
+ this.money = money;
+ }
}
diff --git a/src/main/java/lotto/model/domain/WinningType.java b/src/main/java/lotto/model/domain/WinningType.java
index d6bc206..097a82b 100644
--- a/src/main/java/lotto/model/domain/WinningType.java
+++ b/src/main/java/lotto/model/domain/WinningType.java
@@ -5,8 +5,7 @@ public enum WinningType {
MATCHES_FIVE_WITH_BONUS("5๊ฐ ์ผ์น, ๋ณด๋์ค ๋ณผ ์ผ์น (30,000,000์)", 30_000_000),
MATCHES_FIVE("5๊ฐ ์ผ์น (1,500,000์)", 1_500_000),
MATCHES_FOUR("4๊ฐ ์ผ์น (50,000์)", 50_000),
- MATCHES_THREE("3๊ฐ ์ผ์น (5,000์)", 5_000),
- NO_MATCH("๊ฝ (0์)", 0);
+ MATCHES_THREE("3๊ฐ ์ผ์น (5,000์)", 5_000);
private final String message;
private final long profitMoney;
diff --git a/src/main/java/lotto/model/service/LottosWinningChecker.java b/src/main/java/lotto/model/service/LottosWinningChecker.java
index 59d6454..f679c81 100644
--- a/src/main/java/lotto/model/service/LottosWinningChecker.java
+++ b/src/main/java/lotto/model/service/LottosWinningChecker.java
@@ -18,8 +18,8 @@
public class LottosWinningChecker {
- public static LottosWinningStatus generateWinningStatusAndInput(LottoUser lottoUser,
- WinningNumbers winningNumbers) {
+ public static void generateWinningStatusAndInput(LottoUser lottoUser,
+ WinningNumbers winningNumbers) {
Lottos lottos = lottoUser.getLottos();
AtomicInteger matchesThree = new AtomicInteger();
@@ -28,14 +28,16 @@ public static LottosWinningStatus generateWinningStatusAndInput(LottoUser lottoU
AtomicInteger matchesFiveWithBonus = new AtomicInteger();
AtomicInteger matchesSix = new AtomicInteger();
- lottos.getLottos().forEach(lotto -> {
+ lottos.getLottoBundle().forEach(lotto -> {
int matchesCount = getMatchesCount(lotto.getNumbers(), winningNumbers.getWinningLotto().getNumbers());
stackByMatchesCount(lotto, matchesCount, matchesThree, matchesFour, matchesFiveWithBonus, matchesFive,
matchesSix, winningNumbers);
}
);
- return getWinningStatus(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix, lottoUser);
+ lottoUser.setLottosWinningStatus(
+ getWinningStatus(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix, lottoUser));
+// return getWinningStatus(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix, lottoUser);
// inputWinningStatusToUser(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix);
}
@@ -64,6 +66,7 @@ private static double calculateProfitRatio(AtomicInteger matchesThree, AtomicInt
AtomicInteger matchesFiveWithBonus, AtomicInteger matchesSix,
LottoUser lottoUser) {
return (double) getTotalProfitMoney(matchesThree, matchesFour, matchesFive, matchesFiveWithBonus, matchesSix)
+ * 100
/ lottoUser.getMoney();
}
diff --git a/src/test/java/lotto/ApplicationTest.java b/src/test/java/lotto/ApplicationTest.java
index 404cbe1..9c70a0f 100644
--- a/src/test/java/lotto/ApplicationTest.java
+++ b/src/test/java/lotto/ApplicationTest.java
@@ -32,7 +32,7 @@ class ApplicationTest extends NsTest {
"5๊ฐ ์ผ์น, ๋ณด๋์ค ๋ณผ ์ผ์น (30,000,000์) - 0๊ฐ",
"6๊ฐ ์ผ์น (2,000,000,000์) - 0๊ฐ",
"์ด ์์ต๋ฅ ์ 62.5%์
๋๋ค."
- );
+ );
},
List.of(8, 21, 23, 41, 42, 43),
List.of(3, 5, 11, 16, 32, 38),
@@ -42,7 +42,7 @@ class ApplicationTest extends NsTest {
List.of(7, 11, 30, 40, 42, 43),
List.of(2, 13, 22, 32, 38, 45),
List.of(1, 3, 5, 14, 22, 45)
- );
+ );
}
@Test
diff --git a/src/test/java/lotto/view/InputViewTest.java b/src/test/java/lotto/view/InputViewTest.java
index 0129e80..917d9ee 100644
--- a/src/test/java/lotto/view/InputViewTest.java
+++ b/src/test/java/lotto/view/InputViewTest.java
@@ -52,15 +52,6 @@ class InputViewTest {
.hasMessage(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
}
-// @Test
-// void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ๋๋ฝ() {
-// String input = "1,,3,4,5,6";
-// setInput(input);
-// assertThatThrownBy(() -> InputView.winningNumbersInput())
-// .isInstanceOf(IllegalStateException.class)
-// .hasMessage(ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
-// }
-
@Test
void ๋น์ฒจ๋ฒํธ_๋น์ ์_์
๋ ฅ_์ผํ์ค๋ณต_์์ธ๋ฐ์() {
String input = "1,,3,4,5,6";
From e1eebd2cc6c19e39e0fe9e00d914af822ef288ba Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 16:23:24 +0900
Subject: [PATCH 46/47] =?UTF-8?q?Feat(Validation)=20:=20=ED=86=B5=ED=95=A9?=
=?UTF-8?q?=20Validation=20=ED=81=B4=EB=9E=98=EC=8A=A4=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/java/lotto/model/domain/Lotto.java | 51 +-----
.../java/lotto/model/domain/LottoUser.java | 21 +--
src/main/java/lotto/model/domain/Lottos.java | 32 +---
.../model/domain/LottosWinningStatus.java | 14 +-
.../lotto/model/domain/WinningNumbers.java | 32 +---
.../java/lotto/validation/Validation.java | 165 ++++++++++++++++++
src/main/java/lotto/view/InputView.java | 30 +---
src/main/java/lotto/view/OutputView.java | 27 +--
8 files changed, 187 insertions(+), 185 deletions(-)
create mode 100644 src/main/java/lotto/validation/Validation.java
diff --git a/src/main/java/lotto/model/domain/Lotto.java b/src/main/java/lotto/model/domain/Lotto.java
index d2d75ed..9e560dc 100644
--- a/src/main/java/lotto/model/domain/Lotto.java
+++ b/src/main/java/lotto/model/domain/Lotto.java
@@ -1,64 +1,17 @@
package lotto.model.domain;
-import static lotto.validation.ErrorMessage.LOTTO_HAS_DUPLICATED_NUMBER;
-import static lotto.validation.ErrorMessage.LOTTO_NUMBER_OUT_OF_RANGE;
-import static lotto.validation.ErrorMessage.LOTTO_SIZE_NOT_SIX;
-
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import lotto.validation.Validation;
public class Lotto {
- private static final int MIN_LOTTO_NUMBER = 1;
- private static final int MAX_LOTTO_NUMBER = 45;
private final List numbers;
public Lotto(List numbers) {
- validate(numbers);
+ Validation.validationLotto(numbers);
this.numbers = numbers;
}
- private void validate(List numbers) {
- checkSizeOnlySix(numbers);
- checkNumberOutOfRange(numbers);
- checkDuplicatedNumber(numbers);
- }
-
- // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
-
- private void checkSizeOnlySix(List numbers) {
- if (numbers.size() != 6) {
- throw new IllegalArgumentException(LOTTO_SIZE_NOT_SIX.getMessage());
- }
- }
-
- private void checkNumberOutOfRange(List numbers) {
- for (Integer number : numbers) {
- if (isNumberOutOfRange(number)) {
- throw new IllegalArgumentException(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
- }
- }
- }
-
- private void checkDuplicatedNumber(List numbers) {
- Set numbersNotDupl = new HashSet<>();
- for (Integer number : numbers) {
- checkAndAddNumber(numbersNotDupl, number);
- }
- }
-
- private void checkAndAddNumber(Set numbersNotDupl, Integer number) {
- if (numbersNotDupl.contains(number)) {
- throw new IllegalArgumentException(LOTTO_HAS_DUPLICATED_NUMBER.getMessage());
- }
- numbersNotDupl.add(number);
- }
-
- private boolean isNumberOutOfRange(int number) {
- return number < MIN_LOTTO_NUMBER || number > MAX_LOTTO_NUMBER;
- }
-
public List getNumbers() {
return numbers;
}
diff --git a/src/main/java/lotto/model/domain/LottoUser.java b/src/main/java/lotto/model/domain/LottoUser.java
index 4c0d1e5..720c40e 100644
--- a/src/main/java/lotto/model/domain/LottoUser.java
+++ b/src/main/java/lotto/model/domain/LottoUser.java
@@ -1,5 +1,7 @@
package lotto.model.domain;
+import lotto.validation.Validation;
+
public class LottoUser {
private Lottos lottos;
private int money;
@@ -20,28 +22,11 @@ public LottoUser(Lottos lottos, int money) {
public LottoUser(Lottos lottos, int money, LottosWinningStatus lottosWinningStatus) {
this.lottos = lottos;
- validationMoney(money);
+ Validation.validationMoney(money);
this.money = money;
this.lottosWinningStatus = lottosWinningStatus;
}
- private void validationMoney(int money) {
- checkMoneyOutOfRange(money);
- checkMoneyDivisibility(money);
- }
-
- private void checkMoneyDivisibility(int money) {
- if (money % 1000 != 0) {
- throw new IllegalArgumentException();
- }
- }
-
- private void checkMoneyOutOfRange(int money) {
- if (money < 0 || money > 100000) {
- throw new IllegalArgumentException();
- }
- }
-
public Lottos getLottos() {
return lottos;
}
diff --git a/src/main/java/lotto/model/domain/Lottos.java b/src/main/java/lotto/model/domain/Lottos.java
index bdf3056..8b0c18b 100644
--- a/src/main/java/lotto/model/domain/Lottos.java
+++ b/src/main/java/lotto/model/domain/Lottos.java
@@ -1,45 +1,19 @@
package lotto.model.domain;
-import static lotto.validation.ErrorMessage.LOTTOS_COUNT_OUT_OF_RANGE_100;
-import static lotto.validation.ErrorMessage.LOTTOS_SIZE_NOT_MATCH_COUNT;
-
import java.util.List;
+import lotto.validation.Validation;
public class Lottos {
private final int count;
private final List lottoBundle;
public Lottos(int count, List lottoBundle) {
- validationCount(count);
+ Validation.validationCount(count);
this.count = count;
- validationLottos(count, lottoBundle);
+ Validation.validationLottos(count, lottoBundle);
this.lottoBundle = lottoBundle;
}
- private void validationCount(int count) {
- checkCountUnder100(count);
- }
-
- private void checkCountUnder100(int count) {
- if (count > 100) {
- throw new IllegalArgumentException(LOTTOS_COUNT_OUT_OF_RANGE_100.getMessage());
- }
- }
-
- private void validationLottos(int count, List lottos) {
- checkLottosSizeSameCount(count, lottos);
- }
-
- private static void checkLottosSizeSameCount(int count, List lottos) {
- if (lottos.size() != count) {
- throw new IllegalArgumentException(LOTTOS_SIZE_NOT_MATCH_COUNT.getMessage());
- }
- }
-
- public int getCount() {
- return count;
- }
-
public List getLottoBundle() {
return lottoBundle;
}
diff --git a/src/main/java/lotto/model/domain/LottosWinningStatus.java b/src/main/java/lotto/model/domain/LottosWinningStatus.java
index 6529a5f..a917ff3 100644
--- a/src/main/java/lotto/model/domain/LottosWinningStatus.java
+++ b/src/main/java/lotto/model/domain/LottosWinningStatus.java
@@ -1,6 +1,6 @@
package lotto.model.domain;
-import lotto.validation.ErrorMessage;
+import lotto.validation.Validation;
public class LottosWinningStatus {
private final int matchesThree;
@@ -17,20 +17,10 @@ public LottosWinningStatus(int matchesThree, int matchesFour, int matchesFive, i
this.matchesFive = matchesFive;
this.matchesFiveWithBonus = matchesFiveWithBonus;
this.matchesSix = matchesSix;
- validationProfitRatio(profitRatio);
+ Validation.validationProfitRatio(profitRatio);
this.profitRatio = profitRatio;
}
- private void validationProfitRatio(double profitRatio) {
- checkMaxProfitRatio(profitRatio);
- }
-
- private static void checkMaxProfitRatio(double profitRatio) {
- if (profitRatio > (double) WinningType.MATCHES_SIX.getProfitMoney() * 100 / 1000) {
- throw new IllegalArgumentException(ErrorMessage.WINNING_STATUS_PROFIT_RATIO_OVER_MAX.getMessage());
- }
- }
-
public double getProfitRatio() {
return profitRatio;
}
diff --git a/src/main/java/lotto/model/domain/WinningNumbers.java b/src/main/java/lotto/model/domain/WinningNumbers.java
index 711e961..97d5e35 100644
--- a/src/main/java/lotto/model/domain/WinningNumbers.java
+++ b/src/main/java/lotto/model/domain/WinningNumbers.java
@@ -1,46 +1,18 @@
package lotto.model.domain;
-import static lotto.validation.ErrorMessage.BONUS_NUMBER_IS_DUPLICATED;
-import static lotto.validation.ErrorMessage.BONUS_NUMBER_OUT_OF_RANGE;
-
import java.util.List;
+import lotto.validation.Validation;
public class WinningNumbers {
-
- private static final int MIN_LOTTO_NUMBER = 1;
- private static final int MAX_LOTTO_NUMBER = 45;
-
-
private final Lotto winningLotto;
private final int bonusNumber;
public WinningNumbers(List winningLotto, int bonusNumber) {
this.winningLotto = new Lotto(winningLotto);
- validationBonusNumber(winningLotto, bonusNumber);
+ Validation.validationBonusNumber(winningLotto, bonusNumber);
this.bonusNumber = bonusNumber;
}
- public void validationBonusNumber(List winningLotto, int bonusNumber) {
- checkNumberOutOfRange(bonusNumber);
- checkDuplicatedBonusNumber(winningLotto, bonusNumber);
- }
-
- private void checkDuplicatedBonusNumber(List winningLotto, int bonusNumber) {
- if (winningLotto.contains(bonusNumber)) {
- throw new IllegalArgumentException(BONUS_NUMBER_IS_DUPLICATED.getMessage());
- }
- }
-
- private void checkNumberOutOfRange(int bonusNumber) {
- if (isNumberOutOfRange(bonusNumber)) {
- throw new IllegalArgumentException(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
- }
- }
-
- private boolean isNumberOutOfRange(int number) {
- return number < MIN_LOTTO_NUMBER || number > MAX_LOTTO_NUMBER;
- }
-
public Lotto getWinningLotto() {
return winningLotto;
}
diff --git a/src/main/java/lotto/validation/Validation.java b/src/main/java/lotto/validation/Validation.java
new file mode 100644
index 0000000..c0c24b8
--- /dev/null
+++ b/src/main/java/lotto/validation/Validation.java
@@ -0,0 +1,165 @@
+package lotto.validation;
+
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_IS_DUPLICATED;
+import static lotto.validation.ErrorMessage.BONUS_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTOS_COUNT_OUT_OF_RANGE_100;
+import static lotto.validation.ErrorMessage.LOTTOS_SIZE_NOT_MATCH_COUNT;
+import static lotto.validation.ErrorMessage.LOTTO_HAS_DUPLICATED_NUMBER;
+import static lotto.validation.ErrorMessage.LOTTO_NUMBER_OUT_OF_RANGE;
+import static lotto.validation.ErrorMessage.LOTTO_SIZE_NOT_SIX;
+import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
+import static lotto.validation.ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_DOUBLE_COMMA;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
+import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import lotto.model.domain.Lotto;
+import lotto.model.domain.WinningType;
+
+public class Validation {
+ private static final int MIN_LOTTO_NUMBER = 1;
+ private static final int MAX_LOTTO_NUMBER = 45;
+
+ public static void validationLotto(List numbers) {
+ checkSizeOnlySix(numbers);
+ checkNumberOutOfRange(numbers);
+ checkDuplicatedNumber(numbers);
+ }
+
+
+ public static void validationCount(int count) {
+ checkCountUnder100(count);
+ }
+
+ public static void validationProfitRatio(double profitRatio) {
+ checkMaxProfitRatio(profitRatio);
+ }
+
+
+ public static void validationMoney(int money) {
+ checkMoneyOutOfRange(money);
+ checkMoneyDivisibility(money);
+ }
+
+ public static void validationBonusNumber(List winningLotto, int bonusNumber) {
+ checkNumberOutOfRange(bonusNumber);
+ checkDuplicatedBonusNumber(winningLotto, bonusNumber);
+ }
+
+
+ public static void checkPossibleChangeToInt(String moneyForPurchase) {
+ try {
+ Integer.parseInt(moneyForPurchase);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
+ }
+ }
+
+ public static void checkRightCommaFormat(String winningNumbers) {
+ if (winningNumbers.startsWith(",")) {
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
+ }
+ if (winningNumbers.endsWith(",")) {
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
+ }
+ if (winningNumbers.contains(",,")) {
+ throw new IllegalArgumentException(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
+ }
+ }
+
+
+ public static void checkStatusValueMinus(int lottosWinningStatusValue) {
+ if (lottosWinningStatusValue < 0) {
+ throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+ }
+ }
+
+ public static void checkStatusValueMinus(double lottosWinningStatusValue) {
+ if (lottosWinningStatusValue < 0) {
+ throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
+ }
+ }
+
+ private static void checkDuplicatedBonusNumber(List winningLotto, int bonusNumber) {
+ if (winningLotto.contains(bonusNumber)) {
+ throw new IllegalArgumentException(BONUS_NUMBER_IS_DUPLICATED.getMessage());
+ }
+ }
+
+ private static void checkNumberOutOfRange(int bonusNumber) {
+ if (isNumberOutOfRange(bonusNumber)) {
+ throw new IllegalArgumentException(BONUS_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+ }
+
+ private static boolean isNumberOutOfRange(int number) {
+ return number < MIN_LOTTO_NUMBER || number > MAX_LOTTO_NUMBER;
+ }
+
+
+ private static void checkMoneyDivisibility(int money) {
+ if (money % 1000 != 0) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ private static void checkMoneyOutOfRange(int money) {
+ if (money < 0 || money > 100000) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ private static void checkMaxProfitRatio(double profitRatio) {
+ if (profitRatio > (double) WinningType.MATCHES_SIX.getProfitMoney() * 100 / 1000) {
+ throw new IllegalArgumentException(ErrorMessage.WINNING_STATUS_PROFIT_RATIO_OVER_MAX.getMessage());
+ }
+ }
+
+ private static void checkCountUnder100(int count) {
+ if (count > 100) {
+ throw new IllegalArgumentException(LOTTOS_COUNT_OUT_OF_RANGE_100.getMessage());
+ }
+ }
+
+ public static void validationLottos(int count, List lottos) {
+ checkLottosSizeSameCount(count, lottos);
+ }
+
+ private static void checkLottosSizeSameCount(int count, List lottos) {
+ if (lottos.size() != count) {
+ throw new IllegalArgumentException(LOTTOS_SIZE_NOT_MATCH_COUNT.getMessage());
+ }
+ }
+
+ private static void checkSizeOnlySix(List numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(LOTTO_SIZE_NOT_SIX.getMessage());
+ }
+ }
+
+ private static void checkNumberOutOfRange(List numbers) {
+ for (Integer number : numbers) {
+ if (isNumberOutOfRange(number)) {
+ throw new IllegalArgumentException(LOTTO_NUMBER_OUT_OF_RANGE.getMessage());
+ }
+ }
+ }
+
+ private static void checkDuplicatedNumber(List numbers) {
+ Set numbersNotDupl = new HashSet<>();
+ for (Integer number : numbers) {
+ checkAndAddNumber(numbersNotDupl, number);
+ }
+ }
+
+ private static void checkAndAddNumber(Set numbersNotDupl, Integer number) {
+ if (numbersNotDupl.contains(number)) {
+ throw new IllegalArgumentException(LOTTO_HAS_DUPLICATED_NUMBER.getMessage());
+ }
+ numbersNotDupl.add(number);
+ }
+
+}
diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java
index 1a71801..5c7a12d 100644
--- a/src/main/java/lotto/view/InputView.java
+++ b/src/main/java/lotto/view/InputView.java
@@ -1,13 +1,9 @@
package lotto.view;
-import static lotto.validation.ErrorMessage.MONEY_FOR_PURCHASE_NOT_NUMBER;
-import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_DOUBLE_COMMA;
-import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_END_WITH_COMMA;
-import static lotto.validation.ErrorMessage.WINNINGNUMBERS_NOT_START_WITH_COMMA;
-
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
+import lotto.validation.Validation;
import org.kokodak.Console;
public class InputView {
@@ -18,7 +14,7 @@ public static int moneyForPurchaseInput() {
public static List winningNumbersInput() {
String winningNumbers = Console.readLine();
- checkRightCommaFormat(winningNumbers);
+ Validation.checkRightCommaFormat(winningNumbers);
return readNumbersFromConsole(winningNumbers);
}
@@ -29,30 +25,10 @@ public static int bonusNumberInput() {
private static int changeInputToInt(String moneyForPurchase) {
- checkPossibleChangeToInt(moneyForPurchase);
+ Validation.checkPossibleChangeToInt(moneyForPurchase);
return Integer.parseInt(moneyForPurchase);
}
- private static void checkPossibleChangeToInt(String moneyForPurchase) {
- try {
- Integer.parseInt(moneyForPurchase);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException(MONEY_FOR_PURCHASE_NOT_NUMBER.getMessage());
- }
- }
-
- private static void checkRightCommaFormat(String winningNumbers) {
- if (winningNumbers.startsWith(",")) {
- throw new IllegalArgumentException(WINNINGNUMBERS_NOT_START_WITH_COMMA.getMessage());
- }
- if (winningNumbers.endsWith(",")) {
- throw new IllegalArgumentException(WINNINGNUMBERS_NOT_END_WITH_COMMA.getMessage());
- }
- if (winningNumbers.contains(",,")) {
- throw new IllegalArgumentException(WINNINGNUMBERS_NOT_DOUBLE_COMMA.getMessage());
- }
- }
-
public static List readNumbersFromConsole(String winningNumbers) {
return Arrays.stream(winningNumbers.split(",")).map(InputView::changeInputToInt)
diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java
index 2987d9d..5394b24 100644
--- a/src/main/java/lotto/view/OutputView.java
+++ b/src/main/java/lotto/view/OutputView.java
@@ -1,6 +1,5 @@
package lotto.view;
-import static lotto.validation.ErrorMessage.OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS;
import static lotto.view.ViewMessage.BONUS_NUMBER_PROMPT;
import static lotto.view.ViewMessage.LOTTOS_SIZE_PROMPT;
import static lotto.view.ViewMessage.MAIN_WINNING_NUMBERS_PROMPT;
@@ -11,6 +10,7 @@
import java.util.List;
import lotto.model.domain.Lotto;
import lotto.model.domain.LottosWinningStatus;
+import lotto.validation.Validation;
public class OutputView {
@@ -52,28 +52,15 @@ public static void displayErrorMessage(String errorMessage) {
}
private static void validationWinningStatusNumber(LottosWinningStatus lottosWinningStatus) {
- checkStatusValueMinus(lottosWinningStatus.getMatchesThree());
- checkStatusValueMinus(lottosWinningStatus.getMatchesFour());
- checkStatusValueMinus(lottosWinningStatus.getMatchesFive());
- checkStatusValueMinus(lottosWinningStatus.getMatchesFiveWithBonus());
- checkStatusValueMinus(lottosWinningStatus.getMatchesSix());
- checkStatusValueMinus(roundToTwoDigits(lottosWinningStatus.getProfitRatio()));
+ Validation.checkStatusValueMinus(lottosWinningStatus.getMatchesThree());
+ Validation.checkStatusValueMinus(lottosWinningStatus.getMatchesFour());
+ Validation.checkStatusValueMinus(lottosWinningStatus.getMatchesFive());
+ Validation.checkStatusValueMinus(lottosWinningStatus.getMatchesFiveWithBonus());
+ Validation.checkStatusValueMinus(lottosWinningStatus.getMatchesSix());
+ Validation.checkStatusValueMinus(roundToTwoDigits(lottosWinningStatus.getProfitRatio()));
}
private static double roundToTwoDigits(double profitRatio) {
return profitRatio + 0.05;
}
-
- private static void checkStatusValueMinus(int lottosWinningStatusValue) {
- if (lottosWinningStatusValue < 0) {
- throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
- }
- }
-
- private static void checkStatusValueMinus(double lottosWinningStatusValue) {
- if (lottosWinningStatusValue < 0) {
- throw new IllegalArgumentException(OUTPUT_VIEW_WINNING_STATUS_NUMBER_MINUS.getMessage());
- }
- }
-
}
\ No newline at end of file
From d563c1ea45e33179058f1b178b2baeeabc6c86a7 Mon Sep 17 00:00:00 2001
From: jiseop121 <104052493+jiseop121@users.noreply.github.com>
Date: Mon, 25 Mar 2024 16:30:58 +0900
Subject: [PATCH 47/47] =?UTF-8?q?Docs(README)=20:=20=EA=B0=84=EB=9E=B5?=
=?UTF-8?q?=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/README.md | 51 +++++---------------------------------------------
1 file changed, 5 insertions(+), 46 deletions(-)
diff --git a/docs/README.md b/docs/README.md
index 390a9e2..037cd81 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -49,55 +49,14 @@ https://github.com/TEAM-ALOM/java-lotto
#### InputView
- ์ญํ : ์ฌ์ฉ์์ ์
๋ ฅ์ ๋ฐ๋๋ค.
- - [ ] ๋ก๋ ๊ตฌ์
๊ธ์ก ์
๋ ฅ
- - [ ] 1000์ ๋จ์๋ก ์
๋ ฅ
- - [ ] ๋๋์ด ๋จ์ด์ง์ง ์์ ๊ฒฝ์ฐ ์์ธ
- - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ
- - ๋ฒํธ๋ ์ผํ๋ก ๊ตฌ๋ถ
- - [ ] ๋ณด๋์ค ๋ฒํธ ์
๋ ฅ
#### OutputView
-- ์ญํ : ์ถ๋ ฅํ๋ค.
- - [ ] ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] ๊ตฌ๋งค ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] ๊ตฌ๋งคํ Lottos๋ฅผ ์ถ๋ ฅ
- - [ ] ๋น์ฒจ ํต๊ณ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] 3๊ฐ ์ผ์น ~ 6๊ฐ ์ผ์น ๋ณ ๊ธ์ก๊ณผ ๋น์ฒจ ๊ฐ์๋ฅผ ์ถ๋ ฅ
- - [ ] ์์ต๋ฅ ์ถ๋ ฅ
- - [ ] ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] ์
๋ ฅ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] ๊ตฌ์
๊ธ์ก ์
๋ ฅ ๋ฌธ๊ตฌ
- - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ ๋ฌธ๊ตฌ
- - [ ] ๋ณด๋์ค ๋ฒํธ ์
๋ ฅ ๋ฌธ๊ตฌ
- - [ ] ์๋ฌ ๋ฌธ๊ตฌ๋ฅผ ์ถ๋ ฅํ๋ค.
- - [ ] [ERROR]๋ก ์์ํด์ผํ๋ค.
-
-### **Validation** (๋ฃ์๊น ๊ณ ๋ฏผ์ค)
-
-- ์ญํ : ๊ฐ ๊ณ์ธต๋ณ ์กฐ๊ฑด์ ๋ง๋ ๊ฒ์ฆ ์ํ ๋ฐ ์์ธ ์ฒ๋ฆฌ
-
-#### ViewValidation
-
-- ์ญํ : ์ฌ์ฉ์ ์
์ถ๋ ฅ์ ๊ดํ ๊ฒ์ฆ
- - [ ] InputView
- - [ ] ๋ก๋ ๊ตฌ์
๊ธ์ก
- - [ ] ์ซ์์ธ๊ฐ?
- - [ ] ๋น์ฒจ ๋ฒํธ ์
๋ ฅ
- - [ ] ์ผํ๋ก ๊ตฌ๋ถ์ด ๋์๋
- - [ ] ์ผํ๋ก ์์ํ๋๊ฐ
- - [ ] ์ผํ๋ก ๋๋๋๊ฐ
- - [ ] ๋ณด๋์ค ๋ฒํธ
- - [ ] ์ซ์ ์ธ๊ฐ
- - [ ] OutputView
- - [ ] ๊ตฌ๋งค ๋ก๋ ์ถ๋ ฅ
- - [ ] ๋น์ฒจ ํต๊ณ ์ถ๋ ฅ
-
-#### ControllerValidation
-
-#### ModelValidation
-
-- ์ญํ : ๊ฐ ๋ชจ๋ธ ๊ฐ์ฒด์ ๊ดํ ๊ฒ์ฆ
+- ์ญํ : ์
๋ ฅ ๋ฌธ๊ตฌ ๋ฐ ๊ฒฐ๊ณผ ์ถ๋ ฅํ๋ค.
+
+### **Validation**
+
+#### Validation
#### ErrorMessage