From b2fbb7aad99f6e647e537e87d9e98e63292d79a3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 13:58:28 +0900 Subject: [PATCH 01/52] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D/=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..51b4262d7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,30 @@ +# 우테코 menu 문제 + +## 기능 목록 +- inputView + - 메뉴 추천 받을 코치 이름 입력 + - 코치 이름은 최소 2글자, 최대 4글자이다. + - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - 각 코치가 못 먹는 메뉴를 입력 + - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) + +- outputView + - 메뉴 추천 결과 출력 + +- recommend + - 월, 화, 수, 목, 금 각 요일 마다 추천할 카테고리를 무작위로 정한다. + - 각 코치가 월요일에 먹을 메뉴를 추천한다. + +- category + - 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + +- menu + - 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. + +## 에러 처리 + +- inputValidator + - 잘못된 값을 입력할 경우 `IllegalArgumentException`를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + - 코치 이름은 최소 2글자, 최대 4글자이다. + - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) \ No newline at end of file From 4675817a2bf3658b6388f1cf28ad7fc73e1a15f5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:11:24 +0900 Subject: [PATCH 02/52] =?UTF-8?q?feat:=20InputView=20inputCoachName=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/menu/InputView.java diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java new file mode 100644 index 000000000..69260dd18 --- /dev/null +++ b/src/main/java/menu/InputView.java @@ -0,0 +1,30 @@ +package menu; + +import camp.nextstep.edu.missionutils.Console; +import java.util.function.Supplier; + + +public class InputView { + + private final OutputView outputView = new OutputView(); + private final InputValidator inputValidator = new InputValidator(); + + + public CoachNames inputCoachName(){ + return attemptInput(() -> { + outputView.printCoachNameMessage(); + String coachName = Console.readLine(); + inputValidator.validateCommaContain(coachName); + return new CoachNames(coachName); + }); + } + + private T attemptInput(Supplier supplier){ + try{ + return supplier.get(); + }catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + return supplier.get(); + } + } +} From 7ce87d5de32864615484b0693f8dff17b8cf05ee Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:11:47 +0900 Subject: [PATCH 03/52] =?UTF-8?q?feat:=20OutputView=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/menu/OutputView.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/menu/OutputView.java diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java new file mode 100644 index 000000000..e1cdff56c --- /dev/null +++ b/src/main/java/menu/OutputView.java @@ -0,0 +1,12 @@ +package menu; + +public class OutputView { + + public void printCoachNameMessage(){ + System.out.println(ProcessMessage.InputCoachName); + } + + public void printErrorMessage(String error){ + System.out.println(error); + } +} From 18f7aa78fd536da13ad549c5bfdfe820c1aabef8 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:13:23 +0900 Subject: [PATCH 04/52] =?UTF-8?q?feat:=20InputValidator=20validateCommaCon?= =?UTF-8?q?tain=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputValidator.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/menu/InputValidator.java diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/InputValidator.java new file mode 100644 index 000000000..0e66f78e8 --- /dev/null +++ b/src/main/java/menu/InputValidator.java @@ -0,0 +1,10 @@ +package menu; + +public class InputValidator { + + public void validateCommaContain(String coachName){ + if (!coachName.contains(",")){ + throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); + } + } +} From c573db7492a0aa6a69f72fe7c0ee46831aeec7e4 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:13:37 +0900 Subject: [PATCH 05/52] =?UTF-8?q?feat:=20CoachNames=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/menu/CoachNames.java | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/menu/CoachNames.java diff --git a/src/main/java/menu/CoachNames.java b/src/main/java/menu/CoachNames.java new file mode 100644 index 000000000..92eeb00b6 --- /dev/null +++ b/src/main/java/menu/CoachNames.java @@ -0,0 +1,44 @@ +package menu; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CoachNames { + + private final static int MIN_NAME_LENGTH = 2; + private final static int MAX_NAME_LENGTH = 4; + private final static int MIN_COACH_COUNT = 2; + private final static int MAX_COACH_COUNT = 5; + private final static String BY_COMMA = ","; + private final List coachNames = new ArrayList<>(); + + public CoachNames(String name) { + Arrays.stream(name.split(BY_COMMA)) + .forEach(this::addValidateCoachName); + validateCoachNumber(); + } + + private void addValidateCoachName(String name){ + validateCoachCount(name); + coachNames.add(name); + } + + private void validateCoachCount(String name) { + if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) { + throw new IllegalArgumentException( + String.format(ErrorMessage.COACH_NAME_LENGTH_ERROR.toString(), MIN_NAME_LENGTH, MAX_NAME_LENGTH)); + } + } + + private void validateCoachNumber(){ + if (coachNames.size() < MIN_COACH_COUNT || coachNames.size() > MAX_COACH_COUNT){ + throw new IllegalArgumentException( + String.format(ErrorMessage.COACH_NAME_NUMBER_ERROR.toString(), MIN_COACH_COUNT, MAX_COACH_COUNT)); + } + } + + public List getCoachNames() { + return coachNames; + } +} From 1c26ad82cb2d968f2430e0aceac04e3b44069409 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:13:45 +0900 Subject: [PATCH 06/52] =?UTF-8?q?feat:=20ErrorMessage=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/menu/ErrorMessage.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/menu/ErrorMessage.java diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java new file mode 100644 index 000000000..f1456f196 --- /dev/null +++ b/src/main/java/menu/ErrorMessage.java @@ -0,0 +1,20 @@ +package menu; + +public enum ErrorMessage { + + COACH_NAME_LENGTH_ERROR("코치 이름은 %d~%d글자 사이로 입력되어야 합니다."), + COACH_NAME_NUMBER_ERROR("코치는 최소 %d명, 최대 %d명 입력되어야 합니다."), + + INPUT_COMMA_ERROR(", 로 구분되어 이름을 입력해주세요."); + + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return message; + } +} From f72b9626bea8aaca0401e3c24d87b56f4a2c2dd3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:13:51 +0900 Subject: [PATCH 07/52] =?UTF-8?q?feat:=20ProcessMessage=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/menu/ProcessMessage.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/menu/ProcessMessage.java diff --git a/src/main/java/menu/ProcessMessage.java b/src/main/java/menu/ProcessMessage.java new file mode 100644 index 000000000..f9d9737ca --- /dev/null +++ b/src/main/java/menu/ProcessMessage.java @@ -0,0 +1,16 @@ +package menu; + +public enum ProcessMessage { + InputCoachName("코치의 이름을 입력해 주세요. (, 로 구분)"); + + private final String message; + + ProcessMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return message; + } +} From 537bd2e06f42d09cdc0c9904b622c5dce7fb12ee Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:20:08 +0900 Subject: [PATCH 08/52] =?UTF-8?q?test:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=B4=20','=EB=A1=9C=20=EA=B5=AC=EB=B6=84=EB=90=98?= =?UTF-8?q?=EC=96=B4=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EC=A7=80=20=EB=AA=BB?= =?UTF-8?q?=ED=95=98=EB=A9=B4=20=EC=97=90=EB=9F=AC=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ErrorMessage.java | 5 +++-- src/test/java/menu/InputValidateTest.java | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/test/java/menu/InputValidateTest.java diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java index f1456f196..023d21bbb 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/ErrorMessage.java @@ -5,8 +5,9 @@ public enum ErrorMessage { COACH_NAME_LENGTH_ERROR("코치 이름은 %d~%d글자 사이로 입력되어야 합니다."), COACH_NAME_NUMBER_ERROR("코치는 최소 %d명, 최대 %d명 입력되어야 합니다."), - INPUT_COMMA_ERROR(", 로 구분되어 이름을 입력해주세요."); + INPUT_COMMA_ERROR("',' 로 구분되어 이름을 입력해주세요."); + private static final String prefix = "[ERROR] "; private final String message; ErrorMessage(String message) { @@ -15,6 +16,6 @@ public enum ErrorMessage { @Override public String toString() { - return message; + return prefix + message; } } diff --git a/src/test/java/menu/InputValidateTest.java b/src/test/java/menu/InputValidateTest.java new file mode 100644 index 000000000..54e078254 --- /dev/null +++ b/src/test/java/menu/InputValidateTest.java @@ -0,0 +1,20 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +class InputValidateTest { + + private static final String errorMessage = "[ERROR]"; + InputValidator inputValidator = new InputValidator(); + + @Test + @DisplayName("코치 이름이 ','로 구분되어 입력 받지 못하면 에러가 발생한다.") + void validateSplitComma(){ + assertThatThrownBy(() -> inputValidator.validateCommaContain("토미/제임스/포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } +} From abe86851bc36e0328174396513a99b8963d0f9a8 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:36:16 +0900 Subject: [PATCH 09/52] =?UTF-8?q?test:=20CoachNameTest=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 --- src/main/java/menu/CoachNames.java | 4 +-- src/test/java/menu/CoachNameTest.java | 41 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/test/java/menu/CoachNameTest.java diff --git a/src/main/java/menu/CoachNames.java b/src/main/java/menu/CoachNames.java index 92eeb00b6..7e147d59f 100644 --- a/src/main/java/menu/CoachNames.java +++ b/src/main/java/menu/CoachNames.java @@ -20,11 +20,11 @@ public CoachNames(String name) { } private void addValidateCoachName(String name){ - validateCoachCount(name); + validateCoachNameLength(name); coachNames.add(name); } - private void validateCoachCount(String name) { + private void validateCoachNameLength(String name) { if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) { throw new IllegalArgumentException( String.format(ErrorMessage.COACH_NAME_LENGTH_ERROR.toString(), MIN_NAME_LENGTH, MAX_NAME_LENGTH)); diff --git a/src/test/java/menu/CoachNameTest.java b/src/test/java/menu/CoachNameTest.java new file mode 100644 index 000000000..5c1b3cd5f --- /dev/null +++ b/src/test/java/menu/CoachNameTest.java @@ -0,0 +1,41 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; + +class CoachNameTest { + + private static final String errorMessage = "[ERROR]"; + + @Test + @DisplayName("',' 로 구분되어 코치 이름이 List에 저장되는지 확인한다.") + void checkSaveCoachNames(){ + CoachNames coachNames = new CoachNames("토미,제임스,포코"); + + List names = coachNames.getCoachNames(); + + assertThat(names).containsExactly("토미", "제임스", "포코"); + } + + @Test + @DisplayName("코치 이름이 2~4글자 사이로 작성하지 않으면 에러가 발생한다.") + void validateCoachNameLength(){ + assertThatThrownBy(() -> new CoachNames("토미,제임스123,포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } + + @Test + @DisplayName("코치는 최소 2명, 최대 5명으로 작성하지 않으면 에러가 발생한다.") + void validateCoachNumber(){ + assertThatThrownBy(() -> new CoachNames("토미,제임스,포코,우테코,네이버,카카오")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + + } +} From 64cced4ad02ac730dcc5c6e7256bc15b71395e30 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 15:38:17 +0900 Subject: [PATCH 10/52] =?UTF-8?q?docs:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 51b4262d7..7c16c5e04 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,9 +2,9 @@ ## 기능 목록 - inputView - - 메뉴 추천 받을 코치 이름 입력 - - 코치 이름은 최소 2글자, 최대 4글자이다. - - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - [x] 메뉴 추천 받을 코치 이름 입력 + - [x] 코치 이름은 최소 2글자, 최대 4글자이다. + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - 각 코치가 못 먹는 메뉴를 입력 - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) @@ -24,7 +24,7 @@ ## 에러 처리 - inputValidator - - 잘못된 값을 입력할 경우 `IllegalArgumentException`를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. - - 코치 이름은 최소 2글자, 최대 4글자이다. - - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - [x] 잘못된 값을 입력할 경우 `IllegalArgumentException`를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + - [x] 코치 이름은 최소 2글자, 최대 4글자이다. + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) \ No newline at end of file From ddb9812f87b3a45965a5ca5c1707d2f6f8152fcb Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:26:35 +0900 Subject: [PATCH 11/52] =?UTF-8?q?feat:=20InputView=20inputForbiddenMenu=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index 69260dd18..575dd70ad 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -19,6 +19,19 @@ public CoachNames inputCoachName(){ }); } + public ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + return attemptInput(() -> { + for (String coachName: coachNames.getCoachNames()){ + outputView.printCoachesForbiddenMenu(coachName); + String inputMenu = Console.readLine(); + inputValidator.validateForbiddenMenuCount(inputMenu); + forbiddenMenu.add(coachName, inputMenu); + } + return forbiddenMenu; + }); + } + private T attemptInput(Supplier supplier){ try{ return supplier.get(); From f7e734a5037b909792a12e749fc93ffbca06a775 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:26:53 +0900 Subject: [PATCH 12/52] =?UTF-8?q?feat:=20OutputView=20printCoachesForbidde?= =?UTF-8?q?nMenu=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/OutputView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index e1cdff56c..9992b3e0c 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -9,4 +9,8 @@ public void printCoachNameMessage(){ public void printErrorMessage(String error){ System.out.println(error); } + + public void printCoachesForbiddenMenu(String name) { + System.out.println(String.format(ProcessMessage.INPUT_FORBIDDEN_MENU.toString(), name)); + } } From 48180f91dca7b8a096f81ccf939121e2d09531d9 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:28:04 +0900 Subject: [PATCH 13/52] =?UTF-8?q?feat:=20ProcessMessage=20INPUT=5FFORBIDDE?= =?UTF-8?q?N=5FMENU=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/OutputView.java | 2 +- src/main/java/menu/ProcessMessage.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index 9992b3e0c..77f9faf7a 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -3,7 +3,7 @@ public class OutputView { public void printCoachNameMessage(){ - System.out.println(ProcessMessage.InputCoachName); + System.out.println(ProcessMessage.INPUT_COACH_NAME); } public void printErrorMessage(String error){ diff --git a/src/main/java/menu/ProcessMessage.java b/src/main/java/menu/ProcessMessage.java index f9d9737ca..353b213d8 100644 --- a/src/main/java/menu/ProcessMessage.java +++ b/src/main/java/menu/ProcessMessage.java @@ -1,7 +1,8 @@ package menu; public enum ProcessMessage { - InputCoachName("코치의 이름을 입력해 주세요. (, 로 구분)"); + INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), + INPUT_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); private final String message; From 9e3c80982eee99dc3ea4b3a9f33fa309d7b6b4ce Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:28:26 +0900 Subject: [PATCH 14/52] =?UTF-8?q?feat:=20InputValidator=20validateForbidde?= =?UTF-8?q?nMenuCount=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputValidator.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/InputValidator.java index 0e66f78e8..8b27cbf7e 100644 --- a/src/main/java/menu/InputValidator.java +++ b/src/main/java/menu/InputValidator.java @@ -1,5 +1,7 @@ package menu; +import java.util.Arrays; + public class InputValidator { public void validateCommaContain(String coachName){ @@ -7,4 +9,11 @@ public void validateCommaContain(String coachName){ throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); } } + + public void validateForbiddenMenuCount(String forbiddenMenu){ + long forbiddenMenuCount = Arrays.stream(forbiddenMenu.split(",")).count(); + if(forbiddenMenuCount > 2){ + throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); + } + } } From c06ea3df580ff1a6bcf77424a4caa3f2b85e3b7e Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:28:40 +0900 Subject: [PATCH 15/52] =?UTF-8?q?feat:=20ForbiddenMenu=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/menu/ForbiddenMenu.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/menu/ForbiddenMenu.java diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java new file mode 100644 index 000000000..9ff619fd0 --- /dev/null +++ b/src/main/java/menu/ForbiddenMenu.java @@ -0,0 +1,20 @@ +package menu; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class ForbiddenMenu { + + private final Map> forbiddenMenus = new HashMap<>(); + + public void add(String name, String forbiddenMenu) { + forbiddenMenus.put(name, Arrays.stream(forbiddenMenu.split(",")).collect(Collectors.toList())); + } + + public Map> getForbiddenMenus() { + return forbiddenMenus; + } +} From 5372043b20c32f69ce92105a38889564362b8b7a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:43:08 +0900 Subject: [PATCH 16/52] =?UTF-8?q?test:=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=EC=9D=98=20=EA=B0=9C=EC=88=98=EA=B0=80=20?= =?UTF-8?q?=EC=B5=9C=EC=86=8C=200=EA=B0=9C,=20=EC=B5=9C=EB=8C=80=202?= =?UTF-8?q?=EA=B0=9C=EA=B0=80=20=EC=95=84=EB=8B=88=EB=A9=B4=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EA=B0=80=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/InputValidateTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/menu/InputValidateTest.java b/src/test/java/menu/InputValidateTest.java index 54e078254..17a68b35d 100644 --- a/src/test/java/menu/InputValidateTest.java +++ b/src/test/java/menu/InputValidateTest.java @@ -17,4 +17,12 @@ void validateSplitComma(){ .hasMessageContaining(errorMessage); } + + @Test + @DisplayName("못 먹는 메뉴의 개수가 최소 0개, 최대 2개가 아니면 에러가 발생한다.") + void validateForbiddenMenuCount(){ + assertThatThrownBy(() -> inputValidator.validateForbiddenMenuCount("우동,스시,비빔밥")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(errorMessage); + } } From 52dedf273e831ae848c5d6d548c6294eab160a6d Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:43:38 +0900 Subject: [PATCH 17/52] =?UTF-8?q?test:=20ForbiddenMenuTest=20=EC=BD=94?= =?UTF-8?q?=EC=B9=98=20=EB=B3=84=EB=A1=9C=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94?= =?UTF-8?q?=20=EB=A9=94=EB=89=B4=EA=B0=80=20=EC=A0=80=EC=9E=A5=EB=90=98?= =?UTF-8?q?=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 2 +- src/test/java/menu/ForbiddenMenuTest.java | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/java/menu/ForbiddenMenuTest.java diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index 575dd70ad..08671c8b2 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -20,8 +20,8 @@ public CoachNames inputCoachName(){ } public ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ - ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); return attemptInput(() -> { + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); for (String coachName: coachNames.getCoachNames()){ outputView.printCoachesForbiddenMenu(coachName); String inputMenu = Console.readLine(); diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java new file mode 100644 index 000000000..48548db7b --- /dev/null +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -0,0 +1,27 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; +import java.util.Map; + +class ForbiddenMenuTest { + + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + + @Test + @DisplayName("코치 별로 못 먹는 메뉴가 저장되는지 확인한다.") + void checkSaveCoachForbiddenMenu(){ + //given + forbiddenMenu.add("토미", "우동,스시"); + + //when + Map> forbiddenMenus = forbiddenMenu.getForbiddenMenus(); + + //then + assertThat(forbiddenMenus) + .containsEntry("토미", List.of("우동", "스시")); + } +} From f9022c2cd4c21ada7c32e48da46b66d43ddfd061 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 16:54:37 +0900 Subject: [PATCH 18/52] =?UTF-8?q?docs:=20=EA=B0=81=20=EC=BD=94=EC=B9=98?= =?UTF-8?q?=EA=B0=80=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=EB=A5=BC=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 7c16c5e04..10b6811aa 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,8 +5,8 @@ - [x] 메뉴 추천 받을 코치 이름 입력 - [x] 코치 이름은 최소 2글자, 최대 4글자이다. - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - - 각 코치가 못 먹는 메뉴를 입력 - - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) + - [x] 각 코치가 못 먹는 메뉴를 입력 + - [x] 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) - outputView - 메뉴 추천 결과 출력 @@ -27,4 +27,4 @@ - [x] 잘못된 값을 입력할 경우 `IllegalArgumentException`를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. - [x] 코치 이름은 최소 2글자, 최대 4글자이다. - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - - 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) \ No newline at end of file + - [x] 최소 0개, 최대 2개까지 못 먹는 메뉴가 있다. (, 로 구분해서 입력한다.) \ No newline at end of file From a1d5ef8a5c792b8d4758888679208efb001f7db3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 19:47:57 +0900 Subject: [PATCH 19/52] =?UTF-8?q?feat:=20Days=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/menu/Days.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/menu/Days.java diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/Days.java new file mode 100644 index 000000000..e6c9d3644 --- /dev/null +++ b/src/main/java/menu/Days.java @@ -0,0 +1,20 @@ +package menu; + +public enum Days { + MONDAY("월요일"), + TUESDAY("화요일"), + WEDNESDAY("수요일"), + THURSDAY("목요일"), + FRIDAY("금요일"); + + private final String value; + + Days(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} From e72d19d8cc6d0f178964a7fab8530253a289ff52 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 19:48:21 +0900 Subject: [PATCH 20/52] =?UTF-8?q?feat:=20Categories=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/menu/Categories.java | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/menu/Categories.java diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/Categories.java new file mode 100644 index 000000000..a0c8a484c --- /dev/null +++ b/src/main/java/menu/Categories.java @@ -0,0 +1,35 @@ +package menu; + +import java.util.Arrays; +import java.util.function.Predicate; + +public enum Categories { + JAPANESE(1, "일식"), + KOREAN(2, "한식"), + CHINESE(3, "중식"), + ASIAN(4, "아시안"), + WESTERN(5, "양식"); + + private final int number; + private final String type; + + Categories(int number, String type) { + this.number = number; + this.type = type; + } + + public static String getType(int number) { + return Arrays.stream(Categories.values()) + .filter(isSameNumber(number)) + .map(categories -> categories.type) + .findFirst() + .orElse(null); + } + + private static Predicate isSameNumber(int number) { + return categories -> categories.number == number; + } + + + +} From 3f0cf725b7a2b6653b137eddd71d3ab47c3f72fd Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 19:48:44 +0900 Subject: [PATCH 21/52] =?UTF-8?q?feat:=20RecommendCategory=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/menu/RecommendCategory.java | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/menu/RecommendCategory.java diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java new file mode 100644 index 000000000..7099e2772 --- /dev/null +++ b/src/main/java/menu/RecommendCategory.java @@ -0,0 +1,34 @@ +package menu; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.ArrayList; +import java.util.List; + +public class RecommendCategory { + + private static final int CATEGORY_COUNT = 5; + private final List categories = new ArrayList<>(); + + public void recommendCategory() { + while (categories.size() < CATEGORY_COUNT){ + String newCategory = Categories.getType(Randoms.pickNumberInRange(1, 5)); + if (canAddCategory(newCategory)){ + categories.add(newCategory); + } + } + } + + private boolean canAddCategory(String newCategory) { + long count = categories.stream() + .filter(category -> category.equals(newCategory)) + .count(); + return count < 2; + } + + public List getCategories() { + return categories; + } +} + + From bd56796365f289dcb07e73453690a2166394e59f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 19:48:56 +0900 Subject: [PATCH 22/52] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=9C=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=EA=B0=80=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=88=98=20=EB=A7=8C=ED=81=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9D=B4=20=EB=90=98=EB=8A=94=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoryTest.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/menu/CategoryTest.java diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java new file mode 100644 index 000000000..024832f43 --- /dev/null +++ b/src/test/java/menu/CategoryTest.java @@ -0,0 +1,25 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +import java.util.List; + +class CategoryTest { + + RecommendCategory recommendCategory = new RecommendCategory(); + + @Test + @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") + void checkSaveCategories(){ + //given + recommendCategory.recommendCategory(); + + //when + List categories = recommendCategory.getCategories(); + + //then + assertThat(categories.size()).isEqualTo(5); + } +} From 1f3d65cc2f3edd1d61269a93efd4608793824f97 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 19:49:24 +0900 Subject: [PATCH 23/52] =?UTF-8?q?docs:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 10b6811aa..be3d06ddf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ - 각 코치가 월요일에 먹을 메뉴를 추천한다. - category - - 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + - [x] 한 주에 같은 카테고리는 최대 2회까지만 고르며 생성 - menu - 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. From d6320593cc5bbde23fb05a2708257b7426755583 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:18:53 +0900 Subject: [PATCH 24/52] =?UTF-8?q?feat:=20Menus=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/menu/Menus.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/menu/Menus.java diff --git a/src/main/java/menu/Menus.java b/src/main/java/menu/Menus.java new file mode 100644 index 000000000..51deefa8d --- /dev/null +++ b/src/main/java/menu/Menus.java @@ -0,0 +1,33 @@ +package menu; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +public enum Menus { + JAPANESE("일식", List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")), + KOREAN("한식", List.of("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음")), + CHINES("중식", List.of("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채")), + ASIAN("아시안", List.of("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜")), + WESTERN("양식", List.of("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니")); + + private final String type; + private final List foods; + + Menus(String type, List foods) { + this.type = type; + this.foods = foods; + } + + public static List getFoods(String type) { + return Arrays.stream(Menus.values()) + .filter(isSameType(type)) + .map(menus -> menus.foods) + .findFirst() + .orElse(null); + } + + private static Predicate isSameType(String type) { + return menus -> menus.type.equals(type); + } +} From ca660ffbaf75ec1fd2cb0200afe150db16c4246f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:19:05 +0900 Subject: [PATCH 25/52] =?UTF-8?q?feat:=20RecommendMenu=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/menu/RecommendMenu.java | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/menu/RecommendMenu.java diff --git a/src/main/java/menu/RecommendMenu.java b/src/main/java/menu/RecommendMenu.java new file mode 100644 index 000000000..cf7d23d2f --- /dev/null +++ b/src/main/java/menu/RecommendMenu.java @@ -0,0 +1,47 @@ +package menu; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.*; + +public class RecommendMenu { + + private final Map> menus = new HashMap<>(); + + public void recommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory){ + for (String coach : coachNames.getCoachNames()){ + addMenu(forbiddenMenu, recommendCategory, coach); + } + } + + private void addMenu(ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory, String coach) { + List categories = recommendCategory.getCategories(); + int next = 0; + while (isRecommendsMenu(coach, recommendCategory)){ + List menu = Menus.getFoods(categories.get(next++)); + String menuName = Randoms.shuffle(menu).get(0); + if (canAddMenu(coach, menuName, forbiddenMenu)){ + List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); + coachMenus.add(menuName); + menus.put(coach, coachMenus); + } + } + } + + private boolean isRecommendsMenu(String coach, RecommendCategory recommendCategory) { + List coachMenus = menus.getOrDefault(coach, Collections.emptyList()); + return coachMenus.size() < recommendCategory.getCategoryCount(); + } + + private boolean canAddMenu(String coach, String menuName, ForbiddenMenu forbiddenMenu) { + boolean isNotDuplicate = menus.getOrDefault(coach, Collections.emptyList()) + .stream() + .noneMatch(menu -> menu.equals(menuName)); + boolean isNotContainForbiddenMenu = forbiddenMenu.isNotContainForbiddenMenu(coach, menuName); + return isNotDuplicate && isNotContainForbiddenMenu; + } + + public Map> getMenus() { + return menus; + } +} From 884eb932823d88bd1a1f105499b82bc281367bea Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:19:58 +0900 Subject: [PATCH 26/52] =?UTF-8?q?feat:=20ForbiddenMenu=20isNotContainForbi?= =?UTF-8?q?ddenMenu=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ForbiddenMenu.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java index 9ff619fd0..fdc7fe369 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/ForbiddenMenu.java @@ -1,9 +1,6 @@ package menu; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; public class ForbiddenMenu { @@ -14,6 +11,13 @@ public void add(String name, String forbiddenMenu) { forbiddenMenus.put(name, Arrays.stream(forbiddenMenu.split(",")).collect(Collectors.toList())); } + public boolean isNotContainForbiddenMenu(String name, String menu){ + return forbiddenMenus + .getOrDefault(name, Collections.emptyList()) + .stream() + .noneMatch(forbiddenMenu -> forbiddenMenu.equals(menu)); + } + public Map> getForbiddenMenus() { return forbiddenMenus; } From c639b0ed8e0673a89b81ae6595ae35f0639f27cc Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:20:25 +0900 Subject: [PATCH 27/52] =?UTF-8?q?feat:=20RecommendCategory=20getCategoryCo?= =?UTF-8?q?unt=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/menu/RecommendCategory.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java index 7099e2772..dce37c56b 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/RecommendCategory.java @@ -8,6 +8,7 @@ public class RecommendCategory { private static final int CATEGORY_COUNT = 5; + private static final int MAX_DUPLICATE_COUNT = 2; private final List categories = new ArrayList<>(); public void recommendCategory() { @@ -23,12 +24,16 @@ private boolean canAddCategory(String newCategory) { long count = categories.stream() .filter(category -> category.equals(newCategory)) .count(); - return count < 2; + return count < MAX_DUPLICATE_COUNT; } public List getCategories() { return categories; } + + public int getCategoryCount(){ + return categories.size(); + } } From 5143eef416168f65488c4547fdec8032798cc66e Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:20:53 +0900 Subject: [PATCH 28/52] =?UTF-8?q?test:=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=EC=9D=B4=20=EC=97=86=EC=9D=84=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20true=EB=A5=BC=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoryTest.java | 2 +- src/test/java/menu/ForbiddenMenuTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index 024832f43..d82f23043 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -12,7 +12,7 @@ class CategoryTest { @Test @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") - void checkSaveCategories(){ + void checkSaveRecommendCategories(){ //given recommendCategory.recommendCategory(); diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java index 48548db7b..988d25c13 100644 --- a/src/test/java/menu/ForbiddenMenuTest.java +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -24,4 +24,10 @@ void checkSaveCoachForbiddenMenu(){ assertThat(forbiddenMenus) .containsEntry("토미", List.of("우동", "스시")); } + + @Test + @DisplayName("못 먹는 음식이 없을 경우 true를 반환한다.") + void isNotContainForbiddenMenu(){ + assertThat(forbiddenMenu.isNotContainForbiddenMenu("토미", "비빔밥")).isTrue(); + } } From 8f423a8c40e77e2f9866f9aac2f979a043cb0170 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:21:01 +0900 Subject: [PATCH 29/52] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=9C=EB=90=9C=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=EA=B0=80=20=EC=BD=94=EC=B9=98=20=EC=88=98=20?= =?UTF-8?q?=EB=A7=8C=ED=81=BC=20=EC=A0=80=EC=9E=A5=EB=90=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/MenuTest.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/menu/MenuTest.java diff --git a/src/test/java/menu/MenuTest.java b/src/test/java/menu/MenuTest.java new file mode 100644 index 000000000..43adec0a4 --- /dev/null +++ b/src/test/java/menu/MenuTest.java @@ -0,0 +1,25 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + + +class MenuTest { + + CoachNames coachNames = new CoachNames("토미,제임스,포코"); + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + + + + @Test + @DisplayName("추천된 메뉴가 코치 수 만큼 저장되는지 확인한다.") + void checkSaveRecommendMenus(){ + RecommendMenu recommendMenu = new RecommendMenu(); + RecommendCategory recommendCategory = new RecommendCategory(); + recommendCategory.recommendCategory(); + recommendMenu.recommendMenu(coachNames, forbiddenMenu, recommendCategory); + + assertThat(recommendMenu.getMenus().size()).isEqualTo(3); + } +} From 75c77547eb68115013da54ea8d2a2e012658f2da Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 30 Aug 2023 23:21:53 +0900 Subject: [PATCH 30/52] =?UTF-8?q?docs:=20=EC=B6=94=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index be3d06ddf..98ab49238 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,14 +12,14 @@ - 메뉴 추천 결과 출력 - recommend - - 월, 화, 수, 목, 금 각 요일 마다 추천할 카테고리를 무작위로 정한다. - - 각 코치가 월요일에 먹을 메뉴를 추천한다. + - [x] 월, 화, 수, 목, 금 각 요일 마다 추천할 카테고리를 무작위로 정한다. + - [x] 각 코치가 요일에 먹을 메뉴를 추천한다. - category - [x] 한 주에 같은 카테고리는 최대 2회까지만 고르며 생성 - menu - - 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. + - [x] 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. ## 에러 처리 From 954e64767294a291b553a363c8479127989d0957 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:23:34 +0900 Subject: [PATCH 31/52] =?UTF-8?q?feat:=20main=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Application.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..a8ec2f05a 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -2,6 +2,7 @@ public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + MenuController menuController = new MenuController(); + menuController.StartRecommend(); } } From 286a0126d6ac60714d1ed3695a54da596cec67f5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:23:55 +0900 Subject: [PATCH 32/52] =?UTF-8?q?feat:=20Categories=20outputCategories=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Categories.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/Categories.java index a0c8a484c..ae871f3bc 100644 --- a/src/main/java/menu/Categories.java +++ b/src/main/java/menu/Categories.java @@ -10,6 +10,7 @@ public enum Categories { ASIAN(4, "아시안"), WESTERN(5, "양식"); + private static final String CATEGORY = "카테고리"; private final int number; private final String type; @@ -30,6 +31,16 @@ private static Predicate isSameNumber(int number) { return categories -> categories.number == number; } + public static String outputCategories(){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(CATEGORY); + for (Categories categories : Categories.values()){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(categories.type); + } + stringBuilder.append(OutputElement.LAST_ELEMENT); + return stringBuilder.toString(); + } } From 43150ccab82bb4625f8f20565ea4e8c7b2a190ac Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:24:04 +0900 Subject: [PATCH 33/52] =?UTF-8?q?feat:=20Days=20outputDays=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 --- src/main/java/menu/Days.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/Days.java index e6c9d3644..ba0005d0e 100644 --- a/src/main/java/menu/Days.java +++ b/src/main/java/menu/Days.java @@ -7,14 +7,21 @@ public enum Days { THURSDAY("목요일"), FRIDAY("금요일"); + private static final String DIVISION = "구분"; private final String value; Days(String value) { this.value = value; } - public String getValue() { - return value; + public static String outputDays() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(DIVISION); + for (Days days :Days.values()){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(days.value); + } + stringBuilder.append(OutputElement.LAST_ELEMENT); + return stringBuilder.toString(); } - } From 90201e06fbcf3e16eb80c4bb1537eb108268c877 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:24:28 +0900 Subject: [PATCH 34/52] =?UTF-8?q?feat:=20InputView=20printEnter=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/menu/InputView.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index 08671c8b2..17267a1d3 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -14,6 +14,7 @@ public CoachNames inputCoachName(){ return attemptInput(() -> { outputView.printCoachNameMessage(); String coachName = Console.readLine(); + outputView.printEnter(); inputValidator.validateCommaContain(coachName); return new CoachNames(coachName); }); @@ -25,6 +26,7 @@ public ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ for (String coachName: coachNames.getCoachNames()){ outputView.printCoachesForbiddenMenu(coachName); String inputMenu = Console.readLine(); + outputView.printEnter(); inputValidator.validateForbiddenMenuCount(inputMenu); forbiddenMenu.add(coachName, inputMenu); } From 695e065f94329a1036d00cbf3f40761b1d03e039 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:25:07 +0900 Subject: [PATCH 35/52] =?UTF-8?q?feat:=20RecommendMenu=20toString=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/menu/RecommendCategory.java | 2 +- src/main/java/menu/RecommendMenu.java | 25 +++++++++++++++++++---- src/test/java/menu/CategoryTest.java | 2 +- src/test/java/menu/MenuTest.java | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java index dce37c56b..674f11c1b 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/RecommendCategory.java @@ -11,7 +11,7 @@ public class RecommendCategory { private static final int MAX_DUPLICATE_COUNT = 2; private final List categories = new ArrayList<>(); - public void recommendCategory() { + public void createRecommendCategory() { while (categories.size() < CATEGORY_COUNT){ String newCategory = Categories.getType(Randoms.pickNumberInRange(1, 5)); if (canAddCategory(newCategory)){ diff --git a/src/main/java/menu/RecommendMenu.java b/src/main/java/menu/RecommendMenu.java index cf7d23d2f..af7ea6d3a 100644 --- a/src/main/java/menu/RecommendMenu.java +++ b/src/main/java/menu/RecommendMenu.java @@ -8,7 +8,7 @@ public class RecommendMenu { private final Map> menus = new HashMap<>(); - public void recommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory){ + public void createRecommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory){ for (String coach : coachNames.getCoachNames()){ addMenu(forbiddenMenu, recommendCategory, coach); } @@ -18,23 +18,24 @@ private void addMenu(ForbiddenMenu forbiddenMenu, RecommendCategory recommendCat List categories = recommendCategory.getCategories(); int next = 0; while (isRecommendsMenu(coach, recommendCategory)){ - List menu = Menus.getFoods(categories.get(next++)); + List menu = Menus.getFoods(categories.get(next)); String menuName = Randoms.shuffle(menu).get(0); if (canAddMenu(coach, menuName, forbiddenMenu)){ List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); coachMenus.add(menuName); menus.put(coach, coachMenus); + next++; } } } private boolean isRecommendsMenu(String coach, RecommendCategory recommendCategory) { - List coachMenus = menus.getOrDefault(coach, Collections.emptyList()); + List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); return coachMenus.size() < recommendCategory.getCategoryCount(); } private boolean canAddMenu(String coach, String menuName, ForbiddenMenu forbiddenMenu) { - boolean isNotDuplicate = menus.getOrDefault(coach, Collections.emptyList()) + boolean isNotDuplicate = menus.getOrDefault(coach, new ArrayList<>()) .stream() .noneMatch(menu -> menu.equals(menuName)); boolean isNotContainForbiddenMenu = forbiddenMenu.isNotContainForbiddenMenu(coach, menuName); @@ -44,4 +45,20 @@ private boolean canAddMenu(String coach, String menuName, ForbiddenMenu forbidde public Map> getMenus() { return menus; } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + for (String coach: menus.keySet()){ + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(coach); + + for (String menu: menus.get(coach)){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(menu); + } + stringBuilder.append(OutputElement.LAST_ELEMENT).append(OutputElement.NEXT_ELEMENT); + } + return stringBuilder.toString(); + } + } diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index d82f23043..23a39d8e6 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -14,7 +14,7 @@ class CategoryTest { @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") void checkSaveRecommendCategories(){ //given - recommendCategory.recommendCategory(); + recommendCategory.createRecommendCategory(); //when List categories = recommendCategory.getCategories(); diff --git a/src/test/java/menu/MenuTest.java b/src/test/java/menu/MenuTest.java index 43adec0a4..94f5a9b32 100644 --- a/src/test/java/menu/MenuTest.java +++ b/src/test/java/menu/MenuTest.java @@ -17,8 +17,8 @@ class MenuTest { void checkSaveRecommendMenus(){ RecommendMenu recommendMenu = new RecommendMenu(); RecommendCategory recommendCategory = new RecommendCategory(); - recommendCategory.recommendCategory(); - recommendMenu.recommendMenu(coachNames, forbiddenMenu, recommendCategory); + recommendCategory.createRecommendCategory(); + recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); assertThat(recommendMenu.getMenus().size()).isEqualTo(3); } From 49144e45f0707a7f14d6632e245d933950bcffae Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:25:40 +0900 Subject: [PATCH 36/52] =?UTF-8?q?feat:=20MenuController=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/menu/ForbiddenMenu.java | 2 +- src/main/java/menu/MenuController.java | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/MenuController.java diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java index fdc7fe369..e0d612f64 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/ForbiddenMenu.java @@ -13,7 +13,7 @@ public void add(String name, String forbiddenMenu) { public boolean isNotContainForbiddenMenu(String name, String menu){ return forbiddenMenus - .getOrDefault(name, Collections.emptyList()) + .getOrDefault(name, new ArrayList<>()) .stream() .noneMatch(forbiddenMenu -> forbiddenMenu.equals(menu)); } diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/MenuController.java new file mode 100644 index 000000000..0b644f1bb --- /dev/null +++ b/src/main/java/menu/MenuController.java @@ -0,0 +1,25 @@ +package menu; + +public class MenuController { + + private final InputView inputView; + private final OutputView outputView; + private final RecommendCategory recommendCategory; + private final RecommendMenu recommendMenu; + + public MenuController() { + this.inputView = new InputView(); + this.outputView = new OutputView(); + this.recommendCategory = new RecommendCategory(); + this.recommendMenu = new RecommendMenu(); + } + + public void StartRecommend(){ + outputView.printStartMenu(); + CoachNames coachNames = inputView.inputCoachName(); + ForbiddenMenu forbiddenMenu = inputView.inputForbiddenMenu(coachNames); + recommendCategory.createRecommendCategory(); + recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); + outputView.printRecommendResult(recommendMenu); + } +} From aa0bc6f207aa24eb87cc3caa6844e0908732773a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:25:47 +0900 Subject: [PATCH 37/52] =?UTF-8?q?feat:=20OutputElement=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/menu/OutputElement.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/menu/OutputElement.java diff --git a/src/main/java/menu/OutputElement.java b/src/main/java/menu/OutputElement.java new file mode 100644 index 000000000..65d43b1c7 --- /dev/null +++ b/src/main/java/menu/OutputElement.java @@ -0,0 +1,20 @@ +package menu; + +public enum OutputElement { + FIRST_ELEMENT("[ "), + MIDDLE_ELEMENT(" | "), + LAST_ELEMENT(" ]"), + NEXT_ELEMENT("\n"); + + + private final String element; + + OutputElement(String element) { + this.element = element; + } + + @Override + public String toString() { + return element; + } +} From 1ce2c9d1407b4b3d6970aeffd52d6666fd4ddf44 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:26:02 +0900 Subject: [PATCH 38/52] =?UTF-8?q?feat:=20ProcessMessage=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/menu/ProcessMessage.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ProcessMessage.java b/src/main/java/menu/ProcessMessage.java index 353b213d8..ec3389376 100644 --- a/src/main/java/menu/ProcessMessage.java +++ b/src/main/java/menu/ProcessMessage.java @@ -2,7 +2,10 @@ public enum ProcessMessage { INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), - INPUT_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); + INPUT_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), + OUTPUT_START_MENU("점심 메뉴 추천을 시작합니다."), + OUTPUT_RESULT_MENU("메뉴 추천 결과입니다."), + OUTPUT_FINISH_MENU("추천을 완료했습니다."); private final String message; From cd3d868d63c548207880afc18c734b60efc723c9 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:26:17 +0900 Subject: [PATCH 39/52] =?UTF-8?q?feat:=20OutputView=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/menu/OutputView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index 77f9faf7a..92a22e842 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -13,4 +13,21 @@ public void printErrorMessage(String error){ public void printCoachesForbiddenMenu(String name) { System.out.println(String.format(ProcessMessage.INPUT_FORBIDDEN_MENU.toString(), name)); } + + public void printStartMenu() { + System.out.println(ProcessMessage.OUTPUT_START_MENU); + printEnter(); + } + + public void printEnter(){ + System.out.println(); + } + + public void printRecommendResult(RecommendMenu recommendMenu) { + System.out.println(ProcessMessage.OUTPUT_RESULT_MENU); + System.out.println(Days.outputDays()); + System.out.println(Categories.outputCategories()); + System.out.println(recommendMenu); + System.out.println(ProcessMessage.OUTPUT_FINISH_MENU); + } } From c70a7004243713a165626eb6aed6bf976ae079ec Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:42:09 +0900 Subject: [PATCH 40/52] =?UTF-8?q?refactor:=20Category=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Categories.java | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/Categories.java index ae871f3bc..1b9f8202b 100644 --- a/src/main/java/menu/Categories.java +++ b/src/main/java/menu/Categories.java @@ -10,7 +10,7 @@ public enum Categories { ASIAN(4, "아시안"), WESTERN(5, "양식"); - private static final String CATEGORY = "카테고리"; + private final int number; private final String type; @@ -30,17 +30,4 @@ public static String getType(int number) { private static Predicate isSameNumber(int number) { return categories -> categories.number == number; } - - public static String outputCategories(){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(OutputElement.FIRST_ELEMENT).append(CATEGORY); - for (Categories categories : Categories.values()){ - stringBuilder.append(OutputElement.MIDDLE_ELEMENT) - .append(categories.type); - } - stringBuilder.append(OutputElement.LAST_ELEMENT); - return stringBuilder.toString(); - } - - } From 1e704a331901638a8a2f3f2ac83ed39e8558242f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 01:42:36 +0900 Subject: [PATCH 41/52] =?UTF-8?q?refactor:=20RecommendCategory=20toString?= =?UTF-8?q?=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/menu/MenuController.java | 2 +- src/main/java/menu/OutputView.java | 4 ++-- src/main/java/menu/RecommendCategory.java | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/MenuController.java index 0b644f1bb..2c87b284b 100644 --- a/src/main/java/menu/MenuController.java +++ b/src/main/java/menu/MenuController.java @@ -20,6 +20,6 @@ public void StartRecommend(){ ForbiddenMenu forbiddenMenu = inputView.inputForbiddenMenu(coachNames); recommendCategory.createRecommendCategory(); recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); - outputView.printRecommendResult(recommendMenu); + outputView.printRecommendResult(recommendMenu, recommendCategory); } } diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index 92a22e842..f9337c964 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -23,10 +23,10 @@ public void printEnter(){ System.out.println(); } - public void printRecommendResult(RecommendMenu recommendMenu) { + public void printRecommendResult(RecommendMenu recommendMenu, RecommendCategory recommendCategory) { System.out.println(ProcessMessage.OUTPUT_RESULT_MENU); System.out.println(Days.outputDays()); - System.out.println(Categories.outputCategories()); + System.out.println(recommendCategory); System.out.println(recommendMenu); System.out.println(ProcessMessage.OUTPUT_FINISH_MENU); } diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java index 674f11c1b..c0937208c 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/RecommendCategory.java @@ -7,6 +7,7 @@ public class RecommendCategory { + private static final String CATEGORY = "카테고리"; private static final int CATEGORY_COUNT = 5; private static final int MAX_DUPLICATE_COUNT = 2; private final List categories = new ArrayList<>(); @@ -34,6 +35,18 @@ public List getCategories() { public int getCategoryCount(){ return categories.size(); } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(OutputElement.FIRST_ELEMENT).append(CATEGORY); + for (String category : categories){ + stringBuilder.append(OutputElement.MIDDLE_ELEMENT) + .append(category); + } + stringBuilder.append(OutputElement.LAST_ELEMENT); + return stringBuilder.toString(); + } } From 56740fe808ffcf680d7c455c59fa552643acf039 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 02:11:58 +0900 Subject: [PATCH 42/52] =?UTF-8?q?refactor:=20Input=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 60 +++++++++++++++----------- src/main/java/menu/MenuController.java | 4 +- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index 17267a1d3..a1a49fb98 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -1,7 +1,6 @@ package menu; import camp.nextstep.edu.missionutils.Console; -import java.util.function.Supplier; public class InputView { @@ -9,37 +8,50 @@ public class InputView { private final OutputView outputView = new OutputView(); private final InputValidator inputValidator = new InputValidator(); + public CoachNames readCoachName(){ + CoachNames coachNames; + do { + coachNames = inputCoachName(); + }while (coachNames == null); + return coachNames; + } - public CoachNames inputCoachName(){ - return attemptInput(() -> { - outputView.printCoachNameMessage(); - String coachName = Console.readLine(); - outputView.printEnter(); + + private CoachNames inputCoachName(){ + outputView.printCoachNameMessage(); + String coachName = Console.readLine(); + outputView.printEnter(); + try{ inputValidator.validateCommaContain(coachName); return new CoachNames(coachName); - }); + } catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + return null; + } } - public ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ - return attemptInput(() -> { - ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); - for (String coachName: coachNames.getCoachNames()){ - outputView.printCoachesForbiddenMenu(coachName); - String inputMenu = Console.readLine(); - outputView.printEnter(); + public ForbiddenMenu readForbiddenMenu(CoachNames coachNames){ + ForbiddenMenu forbiddenMenu; + do { + forbiddenMenu = inputForbiddenMenu(coachNames); + }while (forbiddenMenu == null); + return forbiddenMenu; + } + + private ForbiddenMenu inputForbiddenMenu(CoachNames coachNames){ + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + for (String coachName: coachNames.getCoachNames()){ + outputView.printCoachesForbiddenMenu(coachName); + String inputMenu = Console.readLine(); + outputView.printEnter(); + try { inputValidator.validateForbiddenMenuCount(inputMenu); forbiddenMenu.add(coachName, inputMenu); + }catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + return null; } - return forbiddenMenu; - }); - } - - private T attemptInput(Supplier supplier){ - try{ - return supplier.get(); - }catch (IllegalArgumentException e){ - outputView.printErrorMessage(e.getMessage()); - return supplier.get(); } + return forbiddenMenu; } } diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/MenuController.java index 2c87b284b..c64b2e8d9 100644 --- a/src/main/java/menu/MenuController.java +++ b/src/main/java/menu/MenuController.java @@ -16,8 +16,8 @@ public MenuController() { public void StartRecommend(){ outputView.printStartMenu(); - CoachNames coachNames = inputView.inputCoachName(); - ForbiddenMenu forbiddenMenu = inputView.inputForbiddenMenu(coachNames); + CoachNames coachNames = inputView.readCoachName(); + ForbiddenMenu forbiddenMenu = inputView.readForbiddenMenu(coachNames); recommendCategory.createRecommendCategory(); recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); outputView.printRecommendResult(recommendMenu, recommendCategory); From c845633ca65430e5373e9fa61ec162b4f1e05bf2 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 02:41:06 +0900 Subject: [PATCH 43/52] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Application.java | 2 ++ src/main/java/menu/{ => constant}/Categories.java | 2 +- src/main/java/menu/{ => constant}/Days.java | 2 +- src/main/java/menu/{ => constant}/ErrorMessage.java | 2 +- src/main/java/menu/{ => constant}/Menus.java | 2 +- src/main/java/menu/{ => constant}/OutputElement.java | 2 +- src/main/java/menu/{ => constant}/ProcessMessage.java | 2 +- src/main/java/menu/{ => controller}/MenuController.java | 9 ++++++++- src/main/java/menu/{ => model}/CoachNames.java | 4 +++- src/main/java/menu/{ => model}/ForbiddenMenu.java | 2 +- src/main/java/menu/{ => model}/RecommendCategory.java | 4 +++- src/main/java/menu/{ => model}/RecommendMenu.java | 7 ++++++- src/main/java/menu/{ => view}/InputView.java | 5 ++++- src/main/java/menu/{ => view}/OutputView.java | 7 ++++++- .../java/menu/{ => view/validate}/InputValidator.java | 4 +++- src/test/java/menu/CategoryTest.java | 1 + src/test/java/menu/CoachNameTest.java | 1 + src/test/java/menu/ForbiddenMenuTest.java | 1 + src/test/java/menu/InputValidateTest.java | 1 + src/test/java/menu/MenuTest.java | 4 ++++ 20 files changed, 50 insertions(+), 14 deletions(-) rename src/main/java/menu/{ => constant}/Categories.java (97%) rename src/main/java/menu/{ => constant}/Days.java (96%) rename src/main/java/menu/{ => constant}/ErrorMessage.java (95%) rename src/main/java/menu/{ => constant}/Menus.java (98%) rename src/main/java/menu/{ => constant}/OutputElement.java (93%) rename src/main/java/menu/{ => constant}/ProcessMessage.java (96%) rename src/main/java/menu/{ => controller}/MenuController.java (80%) rename src/main/java/menu/{ => model}/CoachNames.java (96%) rename src/main/java/menu/{ => model}/ForbiddenMenu.java (97%) rename src/main/java/menu/{ => model}/RecommendCategory.java (94%) rename src/main/java/menu/{ => model}/RecommendMenu.java (92%) rename src/main/java/menu/{ => view}/InputView.java (93%) rename src/main/java/menu/{ => view}/OutputView.java (86%) rename src/main/java/menu/{ => view/validate}/InputValidator.java (89%) diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index a8ec2f05a..16ccfa07c 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,5 +1,7 @@ package menu; +import menu.controller.MenuController; + public class Application { public static void main(String[] args) { MenuController menuController = new MenuController(); diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/constant/Categories.java similarity index 97% rename from src/main/java/menu/Categories.java rename to src/main/java/menu/constant/Categories.java index 1b9f8202b..eacb5c542 100644 --- a/src/main/java/menu/Categories.java +++ b/src/main/java/menu/constant/Categories.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; import java.util.Arrays; import java.util.function.Predicate; diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/constant/Days.java similarity index 96% rename from src/main/java/menu/Days.java rename to src/main/java/menu/constant/Days.java index ba0005d0e..eeb3229ff 100644 --- a/src/main/java/menu/Days.java +++ b/src/main/java/menu/constant/Days.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; public enum Days { MONDAY("월요일"), diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/constant/ErrorMessage.java similarity index 95% rename from src/main/java/menu/ErrorMessage.java rename to src/main/java/menu/constant/ErrorMessage.java index 023d21bbb..980337a2b 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/constant/ErrorMessage.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; public enum ErrorMessage { diff --git a/src/main/java/menu/Menus.java b/src/main/java/menu/constant/Menus.java similarity index 98% rename from src/main/java/menu/Menus.java rename to src/main/java/menu/constant/Menus.java index 51deefa8d..b69965215 100644 --- a/src/main/java/menu/Menus.java +++ b/src/main/java/menu/constant/Menus.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/menu/OutputElement.java b/src/main/java/menu/constant/OutputElement.java similarity index 93% rename from src/main/java/menu/OutputElement.java rename to src/main/java/menu/constant/OutputElement.java index 65d43b1c7..4aa4acb71 100644 --- a/src/main/java/menu/OutputElement.java +++ b/src/main/java/menu/constant/OutputElement.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; public enum OutputElement { FIRST_ELEMENT("[ "), diff --git a/src/main/java/menu/ProcessMessage.java b/src/main/java/menu/constant/ProcessMessage.java similarity index 96% rename from src/main/java/menu/ProcessMessage.java rename to src/main/java/menu/constant/ProcessMessage.java index ec3389376..e050b5b39 100644 --- a/src/main/java/menu/ProcessMessage.java +++ b/src/main/java/menu/constant/ProcessMessage.java @@ -1,4 +1,4 @@ -package menu; +package menu.constant; public enum ProcessMessage { INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/controller/MenuController.java similarity index 80% rename from src/main/java/menu/MenuController.java rename to src/main/java/menu/controller/MenuController.java index c64b2e8d9..4dc67e525 100644 --- a/src/main/java/menu/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,4 +1,11 @@ -package menu; +package menu.controller; + +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; +import menu.view.InputView; +import menu.view.OutputView; public class MenuController { diff --git a/src/main/java/menu/CoachNames.java b/src/main/java/menu/model/CoachNames.java similarity index 96% rename from src/main/java/menu/CoachNames.java rename to src/main/java/menu/model/CoachNames.java index 7e147d59f..1ef1ebe1d 100644 --- a/src/main/java/menu/CoachNames.java +++ b/src/main/java/menu/model/CoachNames.java @@ -1,4 +1,6 @@ -package menu; +package menu.model; + +import menu.constant.ErrorMessage; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/model/ForbiddenMenu.java similarity index 97% rename from src/main/java/menu/ForbiddenMenu.java rename to src/main/java/menu/model/ForbiddenMenu.java index e0d612f64..2855faa55 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/model/ForbiddenMenu.java @@ -1,4 +1,4 @@ -package menu; +package menu.model; import java.util.*; import java.util.stream.Collectors; diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/model/RecommendCategory.java similarity index 94% rename from src/main/java/menu/RecommendCategory.java rename to src/main/java/menu/model/RecommendCategory.java index c0937208c..209999b40 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/model/RecommendCategory.java @@ -1,6 +1,8 @@ -package menu; +package menu.model; import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Categories; +import menu.constant.OutputElement; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/menu/RecommendMenu.java b/src/main/java/menu/model/RecommendMenu.java similarity index 92% rename from src/main/java/menu/RecommendMenu.java rename to src/main/java/menu/model/RecommendMenu.java index af7ea6d3a..df9f01d51 100644 --- a/src/main/java/menu/RecommendMenu.java +++ b/src/main/java/menu/model/RecommendMenu.java @@ -1,6 +1,11 @@ -package menu; +package menu.model; import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Menus; +import menu.constant.OutputElement; +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.model.RecommendCategory; import java.util.*; diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/view/InputView.java similarity index 93% rename from src/main/java/menu/InputView.java rename to src/main/java/menu/view/InputView.java index a1a49fb98..988fb61d2 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,6 +1,9 @@ -package menu; +package menu.view; import camp.nextstep.edu.missionutils.Console; +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.view.validate.InputValidator; public class InputView { diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/view/OutputView.java similarity index 86% rename from src/main/java/menu/OutputView.java rename to src/main/java/menu/view/OutputView.java index f9337c964..5ad610f42 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,4 +1,9 @@ -package menu; +package menu.view; + +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; +import menu.constant.Days; +import menu.constant.ProcessMessage; public class OutputView { diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/view/validate/InputValidator.java similarity index 89% rename from src/main/java/menu/InputValidator.java rename to src/main/java/menu/view/validate/InputValidator.java index 8b27cbf7e..a6df04b87 100644 --- a/src/main/java/menu/InputValidator.java +++ b/src/main/java/menu/view/validate/InputValidator.java @@ -1,4 +1,6 @@ -package menu; +package menu.view.validate; + +import menu.constant.ErrorMessage; import java.util.Arrays; diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index 23a39d8e6..6c0b626c2 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -1,5 +1,6 @@ package menu; +import menu.model.RecommendCategory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/menu/CoachNameTest.java b/src/test/java/menu/CoachNameTest.java index 5c1b3cd5f..f855b7f29 100644 --- a/src/test/java/menu/CoachNameTest.java +++ b/src/test/java/menu/CoachNameTest.java @@ -1,5 +1,6 @@ package menu; +import menu.model.CoachNames; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java index 988d25c13..8e6bc032f 100644 --- a/src/test/java/menu/ForbiddenMenuTest.java +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -1,5 +1,6 @@ package menu; +import menu.model.ForbiddenMenu; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/menu/InputValidateTest.java b/src/test/java/menu/InputValidateTest.java index 17a68b35d..a6f30a005 100644 --- a/src/test/java/menu/InputValidateTest.java +++ b/src/test/java/menu/InputValidateTest.java @@ -1,5 +1,6 @@ package menu; +import menu.view.validate.InputValidator; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; diff --git a/src/test/java/menu/MenuTest.java b/src/test/java/menu/MenuTest.java index 94f5a9b32..ef82e199d 100644 --- a/src/test/java/menu/MenuTest.java +++ b/src/test/java/menu/MenuTest.java @@ -1,5 +1,9 @@ package menu; +import menu.model.CoachNames; +import menu.model.ForbiddenMenu; +import menu.model.RecommendCategory; +import menu.model.RecommendMenu; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; From a177d580f82c1f767e7401eb81af090ec214ca75 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 10:52:10 +0900 Subject: [PATCH 44/52] =?UTF-8?q?test:=20=EC=B6=94=EC=B2=9C=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=EC=97=90=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=A4=91=20=EC=9D=BC=EB=B6=80=EA=B0=80=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EB=90=98=EB=8A=94=EC=A7=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/constant/Categories.java | 4 ++++ src/main/java/menu/model/RecommendMenu.java | 3 --- src/test/java/menu/CategoryTest.java | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/menu/constant/Categories.java b/src/main/java/menu/constant/Categories.java index eacb5c542..fd6dfad9f 100644 --- a/src/main/java/menu/constant/Categories.java +++ b/src/main/java/menu/constant/Categories.java @@ -30,4 +30,8 @@ public static String getType(int number) { private static Predicate isSameNumber(int number) { return categories -> categories.number == number; } + + public String findType(){ + return type; + } } diff --git a/src/main/java/menu/model/RecommendMenu.java b/src/main/java/menu/model/RecommendMenu.java index df9f01d51..cc276eed6 100644 --- a/src/main/java/menu/model/RecommendMenu.java +++ b/src/main/java/menu/model/RecommendMenu.java @@ -3,9 +3,6 @@ import camp.nextstep.edu.missionutils.Randoms; import menu.constant.Menus; import menu.constant.OutputElement; -import menu.model.CoachNames; -import menu.model.ForbiddenMenu; -import menu.model.RecommendCategory; import java.util.*; diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index 6c0b626c2..6f02ff344 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -1,5 +1,6 @@ package menu; +import menu.constant.Categories; import menu.model.RecommendCategory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -13,7 +14,7 @@ class CategoryTest { @Test @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") - void checkSaveRecommendCategories(){ + void checkSaveRecommendCategoriesCount(){ //given recommendCategory.createRecommendCategory(); @@ -23,4 +24,22 @@ void checkSaveRecommendCategories(){ //then assertThat(categories.size()).isEqualTo(5); } + + @Test + @DisplayName("추천 카테고리에 카테고리 중 일부가 저장되는지 확인한다.") + void checkRecommendCategories(){ + //given + recommendCategory.createRecommendCategory(); + + //when + List categories = recommendCategory.getCategories(); + + //then + assertThat(categories).containsAnyOf( + Categories.JAPANESE.findType(), + Categories.KOREAN.findType(), + Categories.CHINESE.findType(), + Categories.ASIAN.findType(), + Categories.WESTERN.findType()); + } } From b8ddd6f412e837c0901f1987061ac246c1f0174b Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:28:20 +0900 Subject: [PATCH 45/52] =?UTF-8?q?refactor:=20StartRecommend=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/MenuController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 4dc67e525..2d8076cc0 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -25,8 +25,11 @@ public void StartRecommend(){ outputView.printStartMenu(); CoachNames coachNames = inputView.readCoachName(); ForbiddenMenu forbiddenMenu = inputView.readForbiddenMenu(coachNames); - recommendCategory.createRecommendCategory(); - recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); + + while (recommendCategory.isRecommending()){ + recommendCategory.createRecommendCategory(); + recommendMenu.createRecommendMenu(coachNames, forbiddenMenu, recommendCategory); + } outputView.printRecommendResult(recommendMenu, recommendCategory); } } From e4c93093233fca40814444069f716625a8eca2be Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:29:04 +0900 Subject: [PATCH 46/52] =?UTF-8?q?refactor:=20RecommendCategory=20curCatego?= =?UTF-8?q?ry=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/model/RecommendCategory.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/menu/model/RecommendCategory.java b/src/main/java/menu/model/RecommendCategory.java index 209999b40..d7dbc4c22 100644 --- a/src/main/java/menu/model/RecommendCategory.java +++ b/src/main/java/menu/model/RecommendCategory.java @@ -13,13 +13,12 @@ public class RecommendCategory { private static final int CATEGORY_COUNT = 5; private static final int MAX_DUPLICATE_COUNT = 2; private final List categories = new ArrayList<>(); + private int curCategory = 0; public void createRecommendCategory() { - while (categories.size() < CATEGORY_COUNT){ - String newCategory = Categories.getType(Randoms.pickNumberInRange(1, 5)); - if (canAddCategory(newCategory)){ - categories.add(newCategory); - } + String newCategory = Categories.getType(Randoms.pickNumberInRange(1, 5)); + if (canAddCategory(newCategory)){ + categories.add(newCategory); } } @@ -30,6 +29,19 @@ private boolean canAddCategory(String newCategory) { return count < MAX_DUPLICATE_COUNT; } + public boolean isRecommending(){ + return categories.size() < CATEGORY_COUNT; + } + + public void nextCategory(){ + curCategory++; + } + + public int getCurCategory() { + return curCategory; + } + + public List getCategories() { return categories; } From 21da46bfac049d340a3408c8e21b086aca8a6656 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:29:26 +0900 Subject: [PATCH 47/52] =?UTF-8?q?refactor:=20RecommendMenu=20createRecomme?= =?UTF-8?q?ndMenu=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/menu/model/RecommendMenu.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/menu/model/RecommendMenu.java b/src/main/java/menu/model/RecommendMenu.java index cc276eed6..49e87d7d8 100644 --- a/src/main/java/menu/model/RecommendMenu.java +++ b/src/main/java/menu/model/RecommendMenu.java @@ -10,23 +10,23 @@ public class RecommendMenu { private final Map> menus = new HashMap<>(); - public void createRecommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory){ + public void createRecommendMenu(CoachNames coachNames, ForbiddenMenu forbiddenMenu + , RecommendCategory recommendCategory){ for (String coach : coachNames.getCoachNames()){ addMenu(forbiddenMenu, recommendCategory, coach); } + recommendCategory.nextCategory(); } private void addMenu(ForbiddenMenu forbiddenMenu, RecommendCategory recommendCategory, String coach) { List categories = recommendCategory.getCategories(); - int next = 0; while (isRecommendsMenu(coach, recommendCategory)){ - List menu = Menus.getFoods(categories.get(next)); + List menu = Menus.getFoods(categories.get(recommendCategory.getCurCategory())); String menuName = Randoms.shuffle(menu).get(0); if (canAddMenu(coach, menuName, forbiddenMenu)){ List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); coachMenus.add(menuName); menus.put(coach, coachMenus); - next++; } } } From 85f6a992a6dccf8da72883e215bd6f4c62d995c0 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:29:47 +0900 Subject: [PATCH 48/52] =?UTF-8?q?refactor:=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EA=B0=80=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=88=98=20=EB=A7=8C=ED=81=BC=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=9D=B4=20=EB=90=98=EB=8A=94=EC=A7=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoryTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index 6f02ff344..974ce0539 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -16,7 +16,9 @@ class CategoryTest { @DisplayName("추천 카테고리가 카테고리 수 만큼 저장이 되는지 확인한다.") void checkSaveRecommendCategoriesCount(){ //given - recommendCategory.createRecommendCategory(); + while (recommendCategory.isRecommending()){ + recommendCategory.createRecommendCategory(); + } //when List categories = recommendCategory.getCategories(); From bc9278ca95aeea4ec7e29d14bd95b5cd4cc58d99 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:59:08 +0900 Subject: [PATCH 49/52] =?UTF-8?q?refactor:=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/view/validate/InputValidator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/view/validate/InputValidator.java b/src/main/java/menu/view/validate/InputValidator.java index a6df04b87..02caeb55f 100644 --- a/src/main/java/menu/view/validate/InputValidator.java +++ b/src/main/java/menu/view/validate/InputValidator.java @@ -6,15 +6,18 @@ public class InputValidator { + private static final String DIVISION = ","; + private static final int MAX_FORBIDDEN_MENU_COUNT = 2; + public void validateCommaContain(String coachName){ - if (!coachName.contains(",")){ + if (!coachName.contains(DIVISION)){ throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); } } public void validateForbiddenMenuCount(String forbiddenMenu){ long forbiddenMenuCount = Arrays.stream(forbiddenMenu.split(",")).count(); - if(forbiddenMenuCount > 2){ + if(forbiddenMenuCount > MAX_FORBIDDEN_MENU_COUNT){ throw new IllegalArgumentException(ErrorMessage.INPUT_COMMA_ERROR.toString()); } } From 47332cad1dc9d51907d2ed7bb163a624e22ee6a1 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:59:21 +0900 Subject: [PATCH 50/52] =?UTF-8?q?test:=20=EC=88=AB=EC=9E=90=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EB=8A=94=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=9D=B4=20=EB=B0=98=ED=99=98=EB=90=98?= =?UTF-8?q?=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoryTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java index 974ce0539..4910e87cc 100644 --- a/src/test/java/menu/CategoryTest.java +++ b/src/test/java/menu/CategoryTest.java @@ -44,4 +44,11 @@ void checkRecommendCategories(){ Categories.ASIAN.findType(), Categories.WESTERN.findType()); } + + @Test + @DisplayName("숫자에 맞는 카테고리 타입이 반환되는지 확인한다.") + void checkCorrectMappingCategoryType(){ + String type = Categories.getType(1); + assertThat(type).isEqualTo("일식"); + } } From 29294e775ce8b423fb59e7f5306b200f9aac21a5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 11:59:29 +0900 Subject: [PATCH 51/52] =?UTF-8?q?test:=20type=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EB=8A=94=20=EC=9D=8C=EC=8B=9D=EB=93=A4=EC=9D=B4=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=EB=90=98=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/MenuTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/menu/MenuTest.java b/src/test/java/menu/MenuTest.java index ef82e199d..3e6040788 100644 --- a/src/test/java/menu/MenuTest.java +++ b/src/test/java/menu/MenuTest.java @@ -1,11 +1,15 @@ package menu; +import menu.constant.Menus; import menu.model.CoachNames; import menu.model.ForbiddenMenu; import menu.model.RecommendCategory; import menu.model.RecommendMenu; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; + +import java.util.List; + import static org.assertj.core.api.Assertions.*; @@ -26,4 +30,11 @@ void checkSaveRecommendMenus(){ assertThat(recommendMenu.getMenus().size()).isEqualTo(3); } + + @Test + @DisplayName("type에 맞는 음식들이 반환되는지 확인한다.") + void checkCorrectMappingMenu(){ + List menus = Menus.getFoods("일식"); + assertThat(menus).isEqualTo(List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")); + } } From 8ca987e01c036c16b752264d69139188e8428d26 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Thu, 31 Aug 2023 18:41:00 +0900 Subject: [PATCH 52/52] =?UTF-8?q?refactor:=20=EC=9D=BD=EA=B8=B0=20?= =?UTF-8?q?=EC=A0=84=EC=9A=A9=20=EB=B9=88=20=EB=A6=AC=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A1=9C=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/menu/model/ForbiddenMenu.java | 2 +- src/main/java/menu/model/RecommendMenu.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/menu/model/ForbiddenMenu.java b/src/main/java/menu/model/ForbiddenMenu.java index 2855faa55..9ae67260b 100644 --- a/src/main/java/menu/model/ForbiddenMenu.java +++ b/src/main/java/menu/model/ForbiddenMenu.java @@ -13,7 +13,7 @@ public void add(String name, String forbiddenMenu) { public boolean isNotContainForbiddenMenu(String name, String menu){ return forbiddenMenus - .getOrDefault(name, new ArrayList<>()) + .getOrDefault(name, Collections.emptyList()) .stream() .noneMatch(forbiddenMenu -> forbiddenMenu.equals(menu)); } diff --git a/src/main/java/menu/model/RecommendMenu.java b/src/main/java/menu/model/RecommendMenu.java index 49e87d7d8..2962f2b0a 100644 --- a/src/main/java/menu/model/RecommendMenu.java +++ b/src/main/java/menu/model/RecommendMenu.java @@ -32,12 +32,12 @@ private void addMenu(ForbiddenMenu forbiddenMenu, RecommendCategory recommendCat } private boolean isRecommendsMenu(String coach, RecommendCategory recommendCategory) { - List coachMenus = menus.getOrDefault(coach, new ArrayList<>()); + List coachMenus = menus.getOrDefault(coach, Collections.emptyList()); return coachMenus.size() < recommendCategory.getCategoryCount(); } private boolean canAddMenu(String coach, String menuName, ForbiddenMenu forbiddenMenu) { - boolean isNotDuplicate = menus.getOrDefault(coach, new ArrayList<>()) + boolean isNotDuplicate = menus.getOrDefault(coach, Collections.emptyList()) .stream() .noneMatch(menu -> menu.equals(menuName)); boolean isNotContainForbiddenMenu = forbiddenMenu.isNotContainForbiddenMenu(coach, menuName);