diff --git a/README.md b/README.md index 47285218057..095cc704702 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - [x] 로또 래퍼 클래스 구현 - [x] 로또 생성자 빈값 입력 예외 처리 검증 - [x] 구입금액 입력 기능 - - [ ] 구입금액 최소 단위 제한(백원 이하 오류 처리) + - [X] 구입금액 최소 단위 제한(백원 이하 오류 처리) - [X] 랜덤 로또 번호 발급 기능 - [x] 로또 래퍼 클래스 반환 - [x] 로또 번호 6자리 생성 @@ -28,3 +28,5 @@ - [x] 수익률 산출 기능 - [X] 보너스 번호 입력 기능 - [X] 2등 상금 추가 +- [X] 수동 발급 추가 +- [x] 예산 지불 추가 diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 49c0803ca32..7c4680d1b17 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -11,22 +11,43 @@ public void simulateLotto() { } private Statistics getStatistics() { - return getLottos().computeStatistic(getWinLotto()); + return getLottos(getBudget()).computeStatistic(getWinLotto()); } private WinLotto getWinLotto() { - return InputView.inputLastWinLotto(); + return InputView.retryableInputLastWinLotto(); } - private Lottos getLottos() { - Lottos lottos = new Lottos(getBudget()); - ResultView.showGeneratedLottos(lottos); + private Lottos getLottos(Budget budget) { + Count manualIssueCount = getManualIssueCount(budget); + + budget = budget.spend(Price.LOTTO, manualIssueCount); + + Lottos manualLottos = getManualIssuedLottos(manualIssueCount); + Lottos autoLottos = getAutoIssuedLottos(budget); + + ResultView.showLottoQuantity(manualLottos, autoLottos); + + Lottos allLottos = manualLottos.combine(autoLottos); + ResultView.showGeneratedLottos(allLottos); + + return allLottos; + } + + private Count getManualIssueCount(Budget budget) { + return InputView.retryableInputSelfIssueCount(budget); + } + + private Lottos getManualIssuedLottos(Count count) { + return InputView.inputSelfIssueLottos(count); + } + private Lottos getAutoIssuedLottos(Budget budget) { + Lottos lottos = new Lottos(budget); return lottos; } private Budget getBudget() { - Budget budget = InputView.inputBuyBudget(); - ResultView.showLottoQuantity(budget.divide(Lotto.LOTTO_PRICE)); + Budget budget = InputView.retryableInputBuyBudget(); return budget; } diff --git a/src/main/java/lotto/domain/Budget.java b/src/main/java/lotto/domain/Budget.java index a9d03ceb02b..0f0ad58c7fd 100644 --- a/src/main/java/lotto/domain/Budget.java +++ b/src/main/java/lotto/domain/Budget.java @@ -1,18 +1,36 @@ package lotto.domain; -public class Budget { +public class Budget{ - private int value; + private int budget; public Budget(int budget) { - this.value = budget; + validMinValue(budget); + this.budget = budget; } - public int getValue() { - return value; + private void validMinValue(int budget) { + if(budget % 1000 != 0) + throw new IllegalArgumentException("100원 단위는 입력할 수 없습니다: " + budget); } - public int divide(int lottoPrice) { - return value / lottoPrice; + public int purchasableQuantity(Price price) { + return price.divide(budget); + } + + public boolean isEnoughToPay(Price price) { + return price.isEnough(budget); + } + + public boolean isEnoughToPay(Price price, int count) { + return price.isEnough(budget, count); + } + + public Budget spend(Price price) { + return new Budget(budget - price.getValue()); + } + + public Budget spend(Price price, Count issueCount) { + return new Budget(budget - price.multiple(issueCount)); } } diff --git a/src/main/java/lotto/domain/Count.java b/src/main/java/lotto/domain/Count.java new file mode 100644 index 00000000000..2bedcffdd31 --- /dev/null +++ b/src/main/java/lotto/domain/Count.java @@ -0,0 +1,47 @@ +package lotto.domain; + +public class Count implements Comparable{ + + private int count; + + public Count(int count) { + this(count, null); + } + + public Count(int count, Budget budget) { + validPositiveValue(count); + validEnableCount(count, budget); + this.count = count; + } + + private void validEnableCount(int count, Budget budget) { + if(budget == null) { + return; + } + if(!budget.isEnoughToPay(Price.LOTTO, count)){ + throw new IllegalArgumentException("구매 가능 수량을 초과했습니다: " + count); + } + } + + private void validPositiveValue(int count) { + if (count < 0) + throw new IllegalArgumentException("양수 값만 입력할 수 있습니다: " + count); + } + + public int getCount() { + return count; + } + + public boolean isPositive() { + return count > 0; + } + + public Count decrease() { + return new Count(count - 1); + } + + @Override + public int compareTo(Count that) { + return this.count - that.count; + } +} diff --git a/src/main/java/lotto/domain/Lotto.java b/src/main/java/lotto/domain/Lotto.java index 897dee85d38..9137a9fdf83 100644 --- a/src/main/java/lotto/domain/Lotto.java +++ b/src/main/java/lotto/domain/Lotto.java @@ -1,35 +1,49 @@ package lotto.domain; -import java.util.List; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; -public class Lotto { +public class Lotto implements Comparable{ public static final int LOTTO_PRICE = 1000; - private List lotto; + private Set lotto; public Lotto() { this(LottoNumbers.issueNumbers()); } - public Lotto(List lotto) { + public Lotto(Set lotto) { validEmpty(lotto); + validLottoSize(lotto); this.lotto = lotto; } - public static Lotto ofNumbers(List lottoNumbers) { + public static Lotto ofNumbers(Set lottoNumbers) { validEmpty(lottoNumbers); - return new Lotto(lottoNumbers.stream().map(LottoNumber::new).collect(Collectors.toList())); + return new Lotto(getLottoNumbers(lottoNumbers)); } - private static void validEmpty(List lotto) { + private static Set getLottoNumbers(Set lottoNumbers) { + return lottoNumbers.stream() + .map(LottoNumber::new) + .collect(Collectors.toSet()); + } + + private static void validEmpty(Set lotto) { if (lotto == null || lotto.isEmpty()) { throw new IllegalArgumentException("입력값이 없습니다"); } } - public List getLotto() { + private static void validLottoSize(Set lotto) { + if(lotto.size() != 6) { + throw new IllegalArgumentException("유효한 Lotto size가 아닙니다: " + lotto.size()); + } + } + + public Set getLotto() { return lotto; } @@ -37,10 +51,25 @@ public int size() { return lotto.size(); } + public boolean isContainBonus(LottoNumber bonus) { + return lotto.contains(bonus); + } + + @Override + public int compareTo(Lotto that) { + Set compareSet = new HashSet<>(lotto); + compareSet.retainAll(that.lotto); + return compareSet.size(); + } + @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Lotto lotto1 = (Lotto) o; return Objects.equals(lotto, lotto1.lotto); } diff --git a/src/main/java/lotto/domain/LottoNumbers.java b/src/main/java/lotto/domain/LottoNumbers.java index 0b58a42e94b..f8e3df6b175 100644 --- a/src/main/java/lotto/domain/LottoNumbers.java +++ b/src/main/java/lotto/domain/LottoNumbers.java @@ -1,8 +1,6 @@ package lotto.domain; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -18,11 +16,11 @@ private static List initialLottoRange() { return lottoNumbers; } - public static List issueNumbers() { + public static Set issueNumbers() { List issueNumbers = new ArrayList<>(LOTTO_NUMBERS); Collections.shuffle(issueNumbers); issueNumbers = issueNumbers.subList(0, LOTTO_SIZE); Collections.sort(issueNumbers); - return issueNumbers; + return new HashSet<>(issueNumbers); } } diff --git a/src/main/java/lotto/domain/Lottos.java b/src/main/java/lotto/domain/Lottos.java index d1b0e7a5e15..91b989ff874 100644 --- a/src/main/java/lotto/domain/Lottos.java +++ b/src/main/java/lotto/domain/Lottos.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.stream.Collectors; +import static lotto.domain.Price.LOTTO; + public class Lottos { private List lottos; @@ -12,6 +14,10 @@ public Lottos(Budget budget) { this(generateLottosBy(budget)); } + public Lottos(Lotto lotto) { + this(List.of(lotto)); + } + public Lottos(List lottos) { this.lottos = lottos; } @@ -19,8 +25,10 @@ public Lottos(List lottos) { private static List generateLottosBy(Budget budget) { List lottos = new ArrayList<>(); - for (int i = 0; i < budget.divide(Lotto.LOTTO_PRICE); i++) { + if (budget.isEnoughToPay(LOTTO)) { + lottos.addAll(generateLottosBy(budget.spend(LOTTO))); lottos.add(new Lotto()); + return lottos; } return lottos; } @@ -29,6 +37,10 @@ public List getLottos() { return lottos; } + public int size() { + return lottos.size(); + } + public Statistics computeStatistic(WinLotto winLotto) { return new Statistics(checkStatisticNumberMatch(winLotto)); } @@ -45,4 +57,11 @@ private static Statistic getStatistic(WinLotto winLotto, Lotto lotto) { winLotto.isContainBonus(lotto) ); } + + public Lottos combine(Lottos lottos) { + List newLottos = new ArrayList<>(this.lottos); + List combineLottos = lottos.getLottos(); + newLottos.addAll(combineLottos); + return new Lottos(newLottos); + } } diff --git a/src/main/java/lotto/domain/Price.java b/src/main/java/lotto/domain/Price.java new file mode 100644 index 00000000000..9443bfae7c9 --- /dev/null +++ b/src/main/java/lotto/domain/Price.java @@ -0,0 +1,32 @@ +package lotto.domain; + +public enum Price { + + LOTTO(1000); + + private final int value; + + Price(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public int multiple(Count count) { + return count.getCount() * value; + } + + public int divide(int budget) { + return budget / value; + } + + public boolean isEnough(int budget) { + return value <= budget; + } + + public boolean isEnough(int budget, int count) { + return value * count <= budget; + } +} diff --git a/src/main/java/lotto/domain/WinLotto.java b/src/main/java/lotto/domain/WinLotto.java index 2c2d7e8f160..4180c66ad9e 100644 --- a/src/main/java/lotto/domain/WinLotto.java +++ b/src/main/java/lotto/domain/WinLotto.java @@ -1,66 +1,50 @@ package lotto.domain; -import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; public class WinLotto { - private List winLotto; + private Lotto winLotto; private LottoNumber bonus; - public WinLotto(List winLotto, LottoNumber bonus) { - validEmpty(winLotto); - this.winLotto = winLotto; - this.bonus = bonus; + public WinLotto(Set lottoNumbers, Integer bonus) { + this.winLotto = new Lotto(getLottoNumbers(lottoNumbers)); + this.bonus = new LottoNumber(bonus); } - public static WinLotto ofNumbers(List lottoNumbers, int bonus) { - validEmpty(lottoNumbers); - return new WinLotto(createLottoNumber(lottoNumbers), createLottoNumber(bonus)); - } - - private static List createLottoNumber(List lottoNumbers) { - return lottoNumbers - .stream() - .map(LottoNumber::new) - .collect(Collectors.toList()); - } - - private static LottoNumber createLottoNumber(int bonus) { - return new LottoNumber(bonus); - } - - private static void validEmpty(List lotto) { - if (lotto == null || lotto.isEmpty()) { - throw new IllegalArgumentException("입력값이 없습니다"); - } - } - - public int size() { - return winLotto.size(); + private static Set getLottoNumbers(Set lottoNumbers) { + return lottoNumbers.stream() + .map(LottoNumber::new) + .collect(Collectors.toSet()); } public int getFeatNumberCount(Lotto lotto) { - return (int) lotto.getLotto().stream() - .filter(value -> this.winLotto.contains(value)) - .count(); + return this.winLotto.compareTo(lotto); } public boolean isContainBonus(Lotto lotto) { - return lotto.getLotto().contains(bonus); + return lotto.isContainBonus(bonus); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - WinLotto lotto1 = (WinLotto) o; - return Objects.equals(winLotto, lotto1.winLotto); + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + WinLotto winLotto = (WinLotto) o; + return Objects.equals(bonus, winLotto.bonus); } @Override public int hashCode() { - return Objects.hash(winLotto); + return Objects.hash(super.hashCode(), bonus); } } diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index ff44716da4c..03284571386 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -2,27 +2,84 @@ import lotto.domain.*; -import java.util.Arrays; -import java.util.List; -import java.util.Scanner; +import java.util.*; +import java.util.function.Supplier; import java.util.stream.Collectors; public class InputView { private static final Scanner SCANNER = new Scanner(System.in); - public static Budget inputBuyBudget() { + public static Object retryableInput(Supplier supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException e) { + showErrorMessage(e); + return retryableInput(supplier); + } catch (Exception e) { + showErrorMessage(e); + return retryableInput(supplier); + } + } + + private static void showErrorMessage(Exception e) { + SCANNER.reset(); + System.out.println(e.getMessage() + " 다시 입력해주세요."); + } + + public static Budget retryableInputBuyBudget() { + return (Budget) retryableInput(InputView::inputBuyBudget); + } + + private static Budget inputBuyBudget() { System.out.println("구입금액을 입력해 주세요."); return new Budget(SCANNER.nextInt()); } - public static WinLotto inputLastWinLotto() { - return WinLotto.ofNumbers(parseLottoNumbers(), parseBonusNumber()); + public static Count retryableInputSelfIssueCount(Budget budget) { + return (Count) retryableInput(() -> InputView.inputSelfIssueCount(budget)); } - private static List parseLottoNumbers() { - System.out.println("지난 주 당첨 번호를 입력해 주세요."); + private static Count inputSelfIssueCount(Budget budget) { + System.out.println("수동으로 구매할 로또 수를 입력해 주세요."); + return new Count(SCANNER.nextInt(), budget); + } + + public static Lottos inputSelfIssueLottos(Count count) { + System.out.println("수동으로 구매할 번호를 입력해 주세요."); SCANNER.nextLine(); + return new Lottos(inputSelfIssueLottosRecursion(count)); + } + + private static List inputSelfIssueLottosRecursion(Count count) { + + List selfIssueLotto = new ArrayList<>(); + if(count.isPositive()) { + selfIssueLotto.addAll(inputSelfIssueLottosRecursion(count.decrease())); + selfIssueLotto.add(retryableInputSelfIssueLottos()); + return selfIssueLotto; + } + return selfIssueLotto; + } + + private static Lotto retryableInputSelfIssueLottos() { + return (Lotto) retryableInput(InputView::inputSelfIssueLotto); + } + + private static Lotto inputSelfIssueLotto() { + return Lotto.ofNumbers(parseInts(split(SCANNER.nextLine()))); + } + + public static WinLotto retryableInputLastWinLotto() { + return (WinLotto) retryableInput(InputView::inputLastWinLotto); + } + + private static WinLotto inputLastWinLotto() { + return new WinLotto(parseLottoNumbers(), parseBonusNumber()); + } + + private static Set parseLottoNumbers() { + System.out.println("지난 주 당첨 번호를 입력해 주세요."); return parseInts(split(SCANNER.nextLine())); } @@ -36,7 +93,9 @@ private static List split(String input) { return Arrays.stream(result).collect(Collectors.toList()); } - private static List parseInts(List input) { - return input.stream().map(Integer::parseInt).collect(Collectors.toList()); + private static Set parseInts(List input) { + return input.stream() + .map(Integer::parseInt) + .collect(Collectors.toSet()); } } diff --git a/src/main/java/lotto/view/ResultView.java b/src/main/java/lotto/view/ResultView.java index f7dc1479018..977eea3ea29 100644 --- a/src/main/java/lotto/view/ResultView.java +++ b/src/main/java/lotto/view/ResultView.java @@ -21,9 +21,15 @@ private static String getResults(Statistics statistics) { .collect(Collectors.joining("\n", "", "\n")); } - private static String createStatisticForm(Statistics statistics, Statistic matcher) { - return matcher.getMatcher() + "개 일치 (" + matcher.getPrice() + ")-" + statistics.getMatchCount(matcher); + return matcher.getMatcher() + "개 일치" + createBonusMatchForm(matcher) + "(" + matcher.getPrice() + ")-" + statistics.getMatchCount(matcher); + } + + private static String createBonusMatchForm (Statistic matcher) { + if (matcher.isBonusRequired()) { + return ", 보너스 볼 일치"; + } + return ""; } private static String createRateForm(Statistics statistics) { @@ -58,7 +64,7 @@ private static String createLottoForm(Lotto lotto) { return result; } - public static void showLottoQuantity(int lottoQuantity) { - System.out.println(lottoQuantity + "개를 구매했습니다."); + public static void showLottoQuantity(Lottos manualLottos, Lottos autoLottos) { + System.out.println("수동으로 " + manualLottos.size() + "장, 자동으로" + autoLottos.size() + "개를 구매했습니다."); } } diff --git a/src/test/java/lotto/domain/BudgetTest.java b/src/test/java/lotto/domain/BudgetTest.java index d8ec58f9798..e45196f0eef 100644 --- a/src/test/java/lotto/domain/BudgetTest.java +++ b/src/test/java/lotto/domain/BudgetTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @DisplayName("도메인 Budget 테스트") class BudgetTest { @@ -12,7 +13,15 @@ class BudgetTest { @Test void canBuyQuantity() { Budget budget = new Budget(14000); - int result = budget.divide(1000); + int result = budget.purchasableQuantity(Price.LOTTO); assertThat(result).isEqualTo(14); } + + @DisplayName("100원 이하 입력 테스트") + @Test + void minBudgetTest() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new Budget(14100)) + .withMessage("100원 단위는 입력할 수 없습니다: 14100"); + } } diff --git a/src/test/java/lotto/domain/CountTest.java b/src/test/java/lotto/domain/CountTest.java new file mode 100644 index 00000000000..636f4a0ef89 --- /dev/null +++ b/src/test/java/lotto/domain/CountTest.java @@ -0,0 +1,28 @@ +package lotto.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +class CountTest { + + @DisplayName("수동 발급 개수 음수 검증") + @Test + void validIsPositive() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new Count(-1)) + .withMessage("양수 값만 입력할 수 있습니다: -1"); + } + + @DisplayName("수동 발급 개수 차감") + @Test + void decrease() { + Count count = new Count(1); + Count decreasedCount = count.decrease(); + + assertThat(count.compareTo(decreasedCount)).isEqualTo(1); + + } +} diff --git a/src/test/java/lotto/domain/LottoNumbersTest.java b/src/test/java/lotto/domain/LottoNumbersTest.java index bce7fcb9fed..5a8764ee375 100644 --- a/src/test/java/lotto/domain/LottoNumbersTest.java +++ b/src/test/java/lotto/domain/LottoNumbersTest.java @@ -4,10 +4,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -20,9 +17,9 @@ class LottoNumbersTest { @BeforeEach void initComputer() { - Lotto lotto1 = Lotto.ofNumbers(List.of(1, 2, 3, 4, 5, 6)); - Lotto lotto2 = Lotto.ofNumbers(List.of(1, 2, 4, 5, 6, 7)); - Lotto lotto3 = Lotto.ofNumbers(List.of(1, 2, 5, 6, 7, 8)); + Lotto lotto1 = Lotto.ofNumbers(Set.of(1, 2, 3, 4, 5, 6)); + Lotto lotto2 = Lotto.ofNumbers(Set.of(1, 2, 4, 5, 6, 7)); + Lotto lotto3 = Lotto.ofNumbers(Set.of(1, 2, 5, 6, 7, 8)); lottos = new Lottos(List.of(lotto1, lotto2, lotto3)); } @@ -35,28 +32,20 @@ void issueNumbers() { @Test void lottoGenerate_range() { List expected = IntStream.range(1, 46).boxed().map(LottoNumber::new).collect(Collectors.toList()); - List result = LottoNumbers.issueNumbers(); + Set result = LottoNumbers.issueNumbers(); assertThat(expected).containsAll(result); } - @DisplayName("로또 번호 원자성 테스트") - @Test - void lottoGenerate_atomic_test() { - List result = LottoNumbers.issueNumbers(); - Set resultSet = result.stream().collect(Collectors.toSet()); - assertThat(resultSet.size()).isEqualTo(result.size()); - } - @DisplayName("로또 번호 정렬 검증") @Test void lottoGenerate_sort_test() { - List result = LottoNumbers.issueNumbers(); + Set result = LottoNumbers.issueNumbers(); - Collections.sort(result); List expected = new ArrayList<>(result); + Collections.sort(expected); - assertThat(result).isEqualTo(expected); + assertThat(result).isEqualTo(new HashSet<>(expected)); } } diff --git a/src/test/java/lotto/domain/LottoTest.java b/src/test/java/lotto/domain/LottoTest.java index ae750e41a5b..976f80f35e4 100644 --- a/src/test/java/lotto/domain/LottoTest.java +++ b/src/test/java/lotto/domain/LottoTest.java @@ -6,9 +6,9 @@ import org.junit.jupiter.params.provider.NullAndEmptySource; import java.util.List; +import java.util.Set; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.*; @DisplayName("도메인 Lotto 테스트") class LottoTest { @@ -16,7 +16,7 @@ class LottoTest { @DisplayName("Lotto 생성자 빈값 예외 테스트") @ParameterizedTest @NullAndEmptySource - void validEmpty(List input) { + void validEmpty(Set input) { assertThatIllegalArgumentException() .isThrownBy(() -> Lotto.ofNumbers(input)) .withMessageMatching("입력값이 없습니다"); @@ -25,9 +25,16 @@ void validEmpty(List input) { @DisplayName("Size 편의 메서드 테스트") @Test void size() { - Lotto givenLotto = Lotto.ofNumbers(List.of(1, 2, 3, 4, 5, 6)); + Lotto givenLotto = Lotto.ofNumbers(Set.of(1, 2, 3, 4, 5, 6)); int result = givenLotto.size(); assertThat(result).isEqualTo(6); } + @DisplayName("로또 사이즈 유효성 테스트") + @Test + void validLottoSize() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> Lotto.ofNumbers(Set.of(1, 2, 3, 4))) + .withMessage("유효한 Lotto size가 아닙니다: 4"); + } } diff --git a/src/test/java/lotto/domain/LottosTest.java b/src/test/java/lotto/domain/LottosTest.java index f435eb8d089..2b1ebd7c184 100644 --- a/src/test/java/lotto/domain/LottosTest.java +++ b/src/test/java/lotto/domain/LottosTest.java @@ -1,6 +1,7 @@ package lotto.domain; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -13,9 +14,8 @@ public class LottosTest { @DisplayName("당첨 통계 산출") @Test void computeStatistic() { - Lotto givenLotto = Lotto.ofNumbers(List.of(1,2,3,4,5,6)); - Lottos lottos = new Lottos(List.of(givenLotto)); - WinLotto winLotto = WinLotto.ofNumbers(List.of(1, 2, 3, 4, 5, 7), 6); + Lottos lottos = new Lottos(Lotto.ofNumbers(Set.of(1, 2, 3, 4, 5, 6))); + WinLotto winLotto = new WinLotto(Set.of(1, 2, 3, 4, 5, 7), 6); Statistics result = lottos.computeStatistic(winLotto); diff --git a/src/test/java/lotto/domain/StatisticTest.java b/src/test/java/lotto/domain/StatisticTest.java index cb569d278b3..6910274b723 100644 --- a/src/test/java/lotto/domain/StatisticTest.java +++ b/src/test/java/lotto/domain/StatisticTest.java @@ -15,13 +15,17 @@ void valueOfMatchNumber() { assertThat(result).isEqualTo(Statistic.FIFTH); } - @DisplayName("Statistic 2등 3등 테스트") + @DisplayName("Statistic 보너스 미포함 등수 테스트") @Test - void valueOfMatchNumber_withBonusOrNot() { + void valueOfMatchNumber_withoutBonus() { + Statistic resultWithBonus = Statistic.valueOfMatchNumber(5, false); + assertThat(resultWithBonus).isEqualTo(Statistic.THIRD); + } + + @DisplayName("Statistic 보너스 포함 등수 테스트") + @Test + void valueOfMatchNumber_withBonus() { Statistic resultWithBonus = Statistic.valueOfMatchNumber(5, true); assertThat(resultWithBonus).isEqualTo(Statistic.SECOND); - - Statistic resultWithoutBonus = Statistic.valueOfMatchNumber(5, false); - assertThat(resultWithoutBonus).isEqualTo(Statistic.THIRD); } } diff --git a/src/test/java/lotto/domain/WinLottoTest.java b/src/test/java/lotto/domain/WinLottoTest.java index 49b479e5ec9..ad0f9981c1a 100644 --- a/src/test/java/lotto/domain/WinLottoTest.java +++ b/src/test/java/lotto/domain/WinLottoTest.java @@ -1,6 +1,7 @@ package lotto.domain; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -13,8 +14,8 @@ class WinLottoTest { @DisplayName("로또 번호 일치 개수 테스트") @Test void getFeatNumberCount() { - Lotto givenLotto = Lotto.ofNumbers(List.of(1, 2, 3, 4, 5, 6)); - WinLotto winLotto = WinLotto.ofNumbers(List.of(1, 5, 6, 7, 8, 9), 5); + Lotto givenLotto = Lotto.ofNumbers(Set.of(1, 2, 3, 4, 5, 6)); + WinLotto winLotto = new WinLotto(Set.of(1, 5, 6, 7, 8, 9), 5); int result = winLotto.getFeatNumberCount(givenLotto); assertThat(result).isEqualTo(3);