Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿš€ 4๋‹จ๊ณ„ - ๋กœ๋˜(์ˆ˜๋™) #3763

Open
wants to merge 7 commits into
base: hhhhhwi
Choose a base branch
from
Open
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,48 @@
~~~

## TODO
- [ ] ์ž…๋ ฅ
- [x] ์ž…๋ ฅ
- ๊ฐ€๊ฒฉ ์ž…๋ ฅ
- ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ
- [ ] ์ถœ๋ ฅ
- [x] ์ถœ๋ ฅ
- ๊ตฌ๋งค ๊ฐœ์ˆ˜ ์ถœ๋ ฅ
- ๋ฐœํ–‰๋œ ๋กœ๋˜ ์ถœ๋ ฅ
- ๊ฒฐ๊ณผ ์ถœ๋ ฅ
- ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ
- [ ] ๋กœ๋˜ ๋ฐœํ–‰
- [x] ๋กœ๋˜ ๋ฐœํ–‰
- ๊ฐ€๊ฒฉ์— ๋งž๋Š” ๊ฐœ์ˆ˜๋งŒํผ ๋กœ๋˜๋ฅผ ์ƒ์„ฑ
- [ ] ๋กœ๋˜
- [x] ๋กœ๋˜
- 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ
- 6๊ฐœ ์ˆซ์ž ์ƒ์„ฑ ๋ฐฉ๋ฒ•
- ์ž๋™ : Collections.shuffle()
- ์ˆ˜๋™ : ์ž…๋ ฅ๊ฐ’
- ์ •๋ ฌ
- Collections.sort()
- [ ] ๊ฒฐ๊ณผ
- [x] ๊ฒฐ๊ณผ
- ๋กœ๋˜์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๊ธˆ์•ก ๋ฆฌํ„ด
- [ ] ์ˆ˜์ต๋ฅ 
- [x] ์ˆ˜์ต๋ฅ 
- ๊ฒฐ๊ณผ์˜ ๋‹น์ฒจ๊ธˆ์•ก์„ ๊ณ„์‚ฐํ•˜์—ฌ ์ˆ˜์ต๋ฅ  ๋ฆฌํ„ด

---

# ๐Ÿš€ 4๋‹จ๊ณ„ - ๋กœ๋˜(์ˆ˜๋™)

---

## ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ
ํ˜„์žฌ ๋กœ๋˜ ์ƒ์„ฑ๊ธฐ๋Š” ์ž๋™ ์ƒ์„ฑ ๊ธฐ๋Šฅ๋งŒ ์ œ๊ณตํ•œ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์ˆ˜๋™์œผ๋กœ ์ถ”์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผ ํ•œ๋‹ค.
์ž…๋ ฅํ•œ ๊ธˆ์•ก, ์ž๋™ ์ƒ์„ฑ ์ˆซ์ž, ์ˆ˜๋™ ์ƒ์„ฑ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋„๋ก ํ•ด์•ผ ํ•œ๋‹ค.


## TODO
- [x] ์ˆ˜๋™ ์ƒ์„ฑ ๊ธฐ๋Šฅ
- Strategy ์ƒ์„ฑ : ์ƒ์„ฑ ์‹œ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„ ๋กœ๋˜๋ฅผ ์ƒ์„ฑ
- LottoMarket ์ƒ์„ฑ ์‹œ strategy๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š” ์ƒ์„ฑ์ž ์ถ”๊ฐ€
- [x] ๋กœ๋˜ ๊ตฌ๋งค
- ๊ฐ€๊ฒฉ, ์ˆ˜๋™ ๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ๊ฐ–๋Š” ์ƒ์„ฑ์ž : ์ž๋™ ๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์‚ฐ
- ์ˆ˜๋™ ๋กœ๋˜์˜ ๊ฐœ์ˆ˜ ๊ฒ€์ฆ ๋ฐ ํ…Œ์ŠคํŠธ ๋ฉ”์†Œ๋“œ ๊ตฌํ˜„
- [ ] ์ž…๋ ฅ
- ์ˆ˜๋™ ๋กœ๋˜ ๊ฐœ์ˆ˜ ์ž…๋ ฅ
- ์ˆ˜๋™ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ
- [ ] ์ถœ๋ ฅ
- ๋กœ๋˜ ๊ตฌ๋งค ๊ฐœ์ˆ˜ : ์ˆ˜๋™ / ์ž๋™ ๊ฐ ์ถœ๋ ฅ
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์š”๊ตฌ์‚ฌํ•ญ ์ •๋ฆฌ ๐Ÿ’ฏ

26 changes: 18 additions & 8 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import lotto.domain.LottoMarket;
import lotto.domain.LottoPrice;
import lotto.domain.LottoResult;
import lotto.domain.WinningNumbers;
import lotto.domain.*;
import lotto.domain.strategy.AutoLottoNumberStrategy;
import lotto.domain.strategy.ManualLottoNumberStrategy;
import lotto.io.InputView;
import lotto.io.PrintView;

public class Main {
public static void main(String[] args) {
LottoPrice lottoPrice = new LottoPrice(InputView.inputPurchasePrice());
int numberOfLotto = lottoPrice.getNumberOfLotto();
PrintView.printNumberOfLotto(numberOfLotto);
LottoPrice lottoPrice = new LottoPrice(InputView.inputPurchasePrice(), InputView.inputNumberOfManualLotto());
int numberOfAutoLotto = lottoPrice.getNumberOfAutoLotto();
int numberOfManualLotto = lottoPrice.getNumberOfManualLotto();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LottoPrice๋ฅผ ํ†ตํ•ด์„œ ์ž๋™, ์ˆ˜๋™ ์ˆ˜๋Ÿ‰์˜ ์—ญํ• ๊ณผ ์ฑ…์ž„์„ ๋ถ€์—ฌํ•˜์‹  ๋ถ€๋ถ„ ๋„ˆ๋ฌด ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘

๋‹ค๋งŒ LottoMarket์— lottoPrice๋ฅผ ์ „๋‹ฌํ•ด์„œ LottoMarket์—์„œ ์ˆ˜๋™๋กœ๋˜๋ฅผ ์‚ฌ๋Š” ์—ญํ• ์„ ํ•˜๋ฉด ์–ด๋–จ๊นŒ์š”??
์ง€๊ธˆ ๊ตฌ์กฐ์—์„œ๋Š” main์ด ์—†๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด ์ˆ˜๋™๋กœ๋˜๋ฅผ ๊ตฌ๋งคํ•  ์ˆ˜๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

์ฐจ๋ผ๋ฆฌ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ˆ˜๋™๋กœ๋˜๋ฒˆํ˜ธ๋ฅผ ๋‹ค ๋ฐ›์€ ๊ฐ’๊ณผ , LottoPrice๋ฅผ LottoMarket์—๊ฒŒ ์ฃผ๊ณ 
lottoMarket.buy๊ฐ™์€ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ๋‚˜๋ฉด ๋กœ๋˜๋ฒˆํ˜ธ๊ฐ€ ๋‹ด๊ธด ํ‹ฐ์ผ“์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ทธ๋Ÿฐ ๊ตฌ์กฐ๋กœ ๊ฐ„๋‹ค๋ฉด
์•„๋งˆ ๊ณ ๋ฏผํ•˜์‹œ๋Š” ๋ถ€๋ถ„์ด ์–ด๋Š์ •๋„ ๊ฐœ์„ ์ด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„


LottoMarket lottoMarket = new LottoMarket(numberOfAutoLotto, new AutoLottoNumberStrategy());

if(numberOfManualLotto > 0) {
PrintView.printAutoLottoGuide();
}

for(int i = 0; i < numberOfManualLotto; i++) {
lottoMarket.addLotto(new ManualLottoNumberStrategy(InputView.inputLottoNumber()));
}

PrintView.printNumberOfLotto(numberOfManualLotto, numberOfAutoLotto);

LottoMarket lottoMarket = new LottoMarket(numberOfLotto);
PrintView.printLottos(lottoMarket.getLottos());

WinningNumbers winningNumbers = new WinningNumbers(InputView.inputWinningNumbers(), InputView.inputBonusNumber());
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/lotto/domain/LottoMarket.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package lotto.domain;

import lotto.domain.strategy.AutoLottoNumberStrategy;
import lotto.domain.strategy.LottoNumberStrategy;

import java.util.List;

public class LottoMarket {
private final Lottos lottos = new Lottos();

public LottoMarket(int numberOfLotto) {
LottoNumberStrategy strategy = new AutoLottoNumberStrategy();

public LottoMarket(int numberOfLotto, LottoNumberStrategy strategy) {
for(int i = 0; i < numberOfLotto; i++) {
lottos.add(new Lotto(strategy));
}
}

public void addLotto(LottoNumberStrategy strategy) {
lottos.add(new Lotto(strategy));
}

public List<Lotto> getLottos() {
return lottos.getLottos();
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/lotto/domain/LottoNumbers.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package lotto.domain;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import static lotto.domain.strategy.LottoNumberStrategy.*;

public class LottoNumbers {
private final List<Integer> lottoNumbers;

public LottoNumbers(List<Integer> lottoNumbers) {
if(new HashSet<>(lottoNumbers).size() != LOTTO_NUMBER_COUNT) {
throw new IllegalArgumentException("๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}

if(lottoNumbers.size() != LOTTO_NUMBER_COUNT) {
throw new IllegalArgumentException("๋ฒˆํ˜ธ๋Š” " + LOTTO_NUMBER_COUNT + "๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}

if(lottoNumbers.stream().anyMatch(x -> x < LOTTO_NUMBER_MIN || x > LOTTO_NUMBER_MAX)) {
throw new IllegalArgumentException("๋ฒˆํ˜ธ๋Š” " + LOTTO_NUMBER_MIN + " ๋ฏธ๋งŒ " + LOTTO_NUMBER_MAX + " ์ดˆ๊ณผ์ธ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ฒ€์ฆํ•˜์‹  ๋ถ€๋ถ„ ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘
๋‹ค๋งŒ Integer์ธ ๋กœ๋˜๋ฒˆํ˜ธ ์ž์ฒด๊ฐ€ ์›์‹œ๊ฐ์ฒดํฌ์žฅ ๋œ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”??
์™œ๋ƒํ•˜๋ฉด WinningNumbers์—์„œ ์‚ฌ์šฉ์ค‘์ธ bonusNumber๋„ ๊ฒฐ๊ตญ ๋กœ๋˜ ๋ฒˆํ˜ธ์ค‘์— ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค ๐Ÿ˜„
๋กœ๋˜ ๋ฒˆํ˜ธ ๋ฒ”์œ„์— ๋Œ€ํ•œ ๊ฒ€์ฆํ•˜๊ณ  ์žˆ๋Š” ์ฝ”๋“œ๊ฐ€ ์ค‘๋ณต์œผ๋กœ ์žˆ๋Š”๋ฐ์š”, ์ด ๋ถ€๋ถ„์ด ์ข€ ์ •๋ฆฌ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ™‡

// AS IS
List<Integer> lottoNumbers;

// TO BE
List<LottoNumber> lottoNumbers;

์ด ๋ถ€๋ถ„ ํ•œ๋ฒˆ ๊ฐœ์„ ๊ฒ€ํ†  ํ•ด์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ™‡


this.lottoNumbers = lottoNumbers.stream()
.sorted()
.collect(Collectors.toList());
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/lotto/domain/LottoPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@
public class LottoPrice {
private static final int LOTTO_PURCHASE = 1000;
private final int price;
private final int numberOfAutoLotto;
private final int numberOfManualLotto;

public LottoPrice(int price) {
if(price < LOTTO_PURCHASE) {
throw new IllegalArgumentException("1000์› ์ด์ƒ์˜ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}
this.price = price;
this.numberOfAutoLotto = price / LOTTO_PURCHASE;
this.numberOfManualLotto = 0;
}

public LottoPrice(int price, int numberOfInputLotto) {
if(price < LOTTO_PURCHASE) {
throw new IllegalArgumentException("1000์› ์ด์ƒ์˜ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}

int maxNumberOfLotto = price / LOTTO_PURCHASE;

if(maxNumberOfLotto < numberOfInputLotto) {
throw new IllegalArgumentException("์ˆ˜๋™ ๋กœ๋˜๋Š” " + maxNumberOfLotto + "์žฅ ๊นŒ์ง€๋งŒ ๊ตฌ๋งคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.");
}

this.price = price;
this.numberOfAutoLotto = price / LOTTO_PURCHASE - numberOfInputLotto;
this.numberOfManualLotto = numberOfInputLotto;
}

public int getPrice() {
return price;
}

public int getNumberOfLotto() {
return price / LOTTO_PURCHASE;
public int getNumberOfAutoLotto() {
return numberOfAutoLotto;
}

public int getNumberOfManualLotto() {
return numberOfManualLotto;
}
}
19 changes: 5 additions & 14 deletions src/main/java/lotto/domain/WinningNumbers.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package lotto.domain;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

import static lotto.domain.strategy.LottoNumberStrategy.*;

public class WinningNumbers {
private final Set<Integer> winningNumbers;
private final LottoNumbers winningNumbers;
private final int bonusNumber;

public WinningNumbers(Set<Integer> winningNumbers, int bonusNumber) {
if(winningNumbers.size() != LOTTO_NUMBER_COUNT) {
throw new IllegalArgumentException("๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” " + LOTTO_NUMBER_COUNT + "๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}

if(winningNumbers.stream().anyMatch(x -> x < LOTTO_NUMBER_MIN || x > LOTTO_NUMBER_MAX)) {
throw new IllegalArgumentException("๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” " + LOTTO_NUMBER_MIN + " ๋ฏธ๋งŒ " + LOTTO_NUMBER_MAX + " ์ดˆ๊ณผ์ธ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}

public WinningNumbers(LottoNumbers winningNumbers, int bonusNumber) {
if(bonusNumber < LOTTO_NUMBER_MIN || bonusNumber > LOTTO_NUMBER_MAX) {
throw new IllegalArgumentException("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” " + LOTTO_NUMBER_MIN + " ๋ฏธ๋งŒ " + LOTTO_NUMBER_MAX + " ์ดˆ๊ณผ์ธ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.");
}
Expand All @@ -28,13 +19,13 @@ public WinningNumbers(Set<Integer> winningNumbers, int bonusNumber) {
}

public WinningNumbers(String[] winningNumbers, int bonusNumber) {
this(Arrays.stream(winningNumbers)
this(new LottoNumbers(Arrays.stream(winningNumbers)
.map(Integer::parseInt)
.collect(Collectors.toSet()), bonusNumber);
.collect(Collectors.toList())), bonusNumber);
}

public Long getMatchedCount(Lotto lotto) {
return winningNumbers.stream()
return winningNumbers.getLottoNumbers().stream()
.filter(lotto::isMatched)
.count();
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/lotto/domain/strategy/ManualLottoNumberStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lotto.domain.strategy;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ManualLottoNumberStrategy implements LottoNumberStrategy{
private final List<Integer> numbers;

public ManualLottoNumberStrategy(List<Integer> numbers) {
this.numbers = numbers;
}

public ManualLottoNumberStrategy(String[] numbers) {
this(Arrays.stream(numbers)
.map(Integer::parseInt)
.collect(Collectors.toList()));
}

@Override
public List<Integer> generateLottoNumber() {
return this.numbers;
}
}
9 changes: 9 additions & 0 deletions src/main/java/lotto/io/InputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public static int inputPurchasePrice() {
return Integer.parseInt(scanner.nextLine());
}

public static int inputNumberOfManualLotto() {
System.out.println("์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋กœ๋˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
return Integer.parseInt(scanner.nextLine());
}

public static String[] inputWinningNumbers() {
System.out.println("์ง€๋‚œ ์ฃผ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
return scanner.nextLine().replace(" ", "").split(",");
Expand All @@ -19,4 +24,8 @@ public static int inputBonusNumber() {
System.out.println("๋ณด๋„ˆ์Šค ๋ณผ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.");
return Integer.parseInt(scanner.nextLine());
}

public static String[] inputLottoNumber() {
return scanner.nextLine().replace(" ", "").split(",");
}
}
8 changes: 6 additions & 2 deletions src/main/java/lotto/io/PrintView.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
public class PrintView {
static StringBuilder stringBuilder = new StringBuilder();

public static void printNumberOfLotto(int number) {
System.out.println(number + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.");
public static void printAutoLottoGuide() {
System.out.println("์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.");
}

public static void printNumberOfLotto(int manualLotto, int autoLotto) {
System.out.println("์ˆ˜๋™์œผ๋กœ "+ manualLotto +"์žฅ, ์ž๋™์œผ๋กœ " + autoLotto + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.");
}

public static void printLottos(List<Lotto> lottos) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/lotto/domain/LottoMarketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class LottoMarketTest {
@Test
void ์ž…๋ ฅํ•œ_๊ฐœ์ˆ˜๋งŒํผ_๋กœ๋˜๋ฅผ_๋ฐœํ–‰ํ•œ๋‹ค() {
int numberOfLotto = 1;
LottoMarket lottoMarket = new LottoMarket(numberOfLotto);
LottoMarket lottoMarket = new LottoMarket(numberOfLotto, () -> List.of(1, 2, 3, 4, 5, 6));
assertThat(lottoMarket.getLottos()).hasSize(numberOfLotto);
}
}
19 changes: 19 additions & 0 deletions src/test/java/lotto/domain/LottoPriceTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package lotto.domain;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

class LottoPriceTest {
Expand All @@ -11,4 +15,19 @@ class LottoPriceTest {
.isThrownBy(() -> new LottoPrice(0))
.withMessageMatching("1000์› ์ด์ƒ์˜ ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.");
}

@ParameterizedTest
@ValueSource(ints = {1, 3, 10})
@DisplayName("์ž๋™ ๋กœ๋˜ ๊ฐœ์ˆ˜ = ๊ธˆ์•ก / 1000 - ์ˆ˜๋™ ๋กœ๋˜ ๊ฐœ์ˆ˜")
void ์ž๋™_๋กœ๋˜_๊ฐœ์ˆ˜_๊ฒ€์ฆ(int number) {
assertThat(new LottoPrice(10000, number).getNumberOfAutoLotto()).isEqualTo(10000 / 1000 - number);
}

@ParameterizedTest
@ValueSource(ints = {10000, 3000, 1000})
void ์ˆ˜๋™_๋กœ๋˜๋Š”_์ด_์ƒ์„ฑ_๊ฐœ์ˆ˜๋ฅผ_๋„˜์„_์ˆ˜_์—†๋‹ค(int price) {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new LottoPrice(price, price / 1000 + 1))
.withMessageMatching("์ˆ˜๋™ ๋กœ๋˜๋Š” " + price / 1000 + "์žฅ ๊นŒ์ง€๋งŒ ๊ตฌ๋งคํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.");
}
}
20 changes: 8 additions & 12 deletions src/test/java/lotto/domain/LottoResultTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package lotto.domain;

import lotto.domain.strategy.LottoNumberStrategy;
import lotto.domain.strategy.ManualLottoNumberStrategy;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -13,13 +13,13 @@
import static org.assertj.core.api.Assertions.assertThat;

public class LottoResultTest {
private final WinningNumbers winningNumbers = new WinningNumbers(Set.of(1, 2, 3, 4, 5, 6), 11);
private static final Lotto twoMatchedLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 7, 8, 9, 10)));
private static final Lotto threeMatchedLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 3, 7, 8, 9)));
private static final Lotto fourMatchedLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 3, 4, 8, 9)));
private static final Lotto fiveMatchedLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 9)));
private static final Lotto fiveMatchedWithBonusLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 11)));
private static final Lotto sixMatchedLotto = new Lotto(getInputLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 6)));
private final WinningNumbers winningNumbers = new WinningNumbers(new LottoNumbers(List.of(1, 2, 3, 4, 5, 6)), 11);
private static final Lotto twoMatchedLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 7, 8, 9, 10)));
private static final Lotto threeMatchedLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 3, 7, 8, 9)));
private static final Lotto fourMatchedLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 3, 4, 8, 9)));
private static final Lotto fiveMatchedLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 9)));
private static final Lotto fiveMatchedWithBonusLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 11)));
private static final Lotto sixMatchedLotto = new Lotto(new ManualLottoNumberStrategy(List.of(1, 2, 3, 4, 5, 6)));
private LottoPrice lottoPrice;

@ParameterizedTest
Expand Down Expand Up @@ -65,8 +65,4 @@ private static Stream<Arguments> getLottoNumbersAndExpectedPrize() {
, Arguments.of(sixMatchedLotto, 2000000000)
);
}

private static LottoNumberStrategy getInputLottoNumberStrategy(List<Integer> inputLottoNumber) {
return () -> inputLottoNumber;
}
}
Loading