-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Step4 - 로또(수동) #4231
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
Step4 - 로또(수동) #4231
Changes from 4 commits
072cd19
ffb12e3
9744613
490fe65
dd72b07
3f9d019
f8de414
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package lotto.domain; | ||
|
|
||
| public class LottoCount { | ||
| private final int manualCount; | ||
| private final int autoCount; | ||
|
|
||
| public LottoCount(Money money, int manualCount) { | ||
| this(money.getBuyableCount() - manualCount, manualCount); | ||
| } | ||
|
|
||
| public LottoCount(int autoCount,int manualCount) { | ||
| this.autoCount = autoCount; | ||
| this.manualCount = manualCount; | ||
| } | ||
|
|
||
| public int getManualCount() { | ||
| return this.manualCount; | ||
| } | ||
|
|
||
| public int getAutoCount() { | ||
| return this.autoCount; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,13 +6,29 @@ | |
| public class LottoGroup { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LottoGroup이 구매한 로또와 관련한 로직을 구현하는 책임과 로또 생성하는 책임을 가지는 것으로 보여진다. 3단계에서 4단계로 요구사항이 변경될 때 로또를 생성하는 부분의 요구사항만 변경됐다. |
||
| private final List<Lotto> lottos; | ||
|
|
||
| public LottoGroup(LottoPurChase lottoPurchase, List<Lotto> manualLottos) { | ||
| this(buyLotto(lottoPurchase, manualLottos)); | ||
| } | ||
|
|
||
| public LottoGroup(Money money) { | ||
| this(buyLotto(money)); | ||
| } | ||
|
|
||
| public LottoGroup(List<Lotto> lottos) { | ||
| this.lottos = lottos; | ||
| } | ||
|
|
||
| private static List<Lotto> buyLotto(LottoPurChase lottoPurchase, List<Lotto> manualLottos) { | ||
| List<Lotto> lottoArray = new ArrayList<>(manualLottos); | ||
|
|
||
| for(int i = 0; i < lottoPurchase.getAutoCount(); i++) { | ||
| lottoArray.add(new Lotto(LottoMachine.createLottoNumbers())); | ||
| } | ||
|
|
||
| return lottoArray; | ||
| } | ||
|
|
||
|
|
||
| private static List<Lotto> buyLotto(Money money) { | ||
| int cnt = money.getBuyableCount(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package lotto.domain; | ||
|
|
||
| public class LottoPurChase { | ||
| private final Money money; | ||
| private final LottoCount lottoCount; | ||
|
|
||
|
|
||
| public LottoPurChase(int money, int autoCount, int manualCount) { | ||
| this(new Money(money), new LottoCount(autoCount, manualCount)); | ||
| } | ||
| public LottoPurChase(Money money, LottoCount lottoCount) { | ||
| this.money = money; | ||
| this.lottoCount = lottoCount; | ||
| } | ||
|
|
||
| public Money getMoney() { | ||
| return this.money; | ||
| } | ||
|
|
||
| public int getAutoCount() { | ||
| return this.lottoCount.getAutoCount(); | ||
| } | ||
|
|
||
| public int getManualCount() { | ||
| return this.lottoCount.getManualCount(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package lotto.domain; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LottoCountTest { | ||
|
|
||
| @Test | ||
| void 수동_자동_카운트해서_생성() { | ||
| LottoCount lottoCount = new LottoCount(11, 3); | ||
|
|
||
| Assertions.assertThat(lottoCount.getAutoCount()).isEqualTo(11); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package lotto.domain; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LottoPurchaseTest { | ||
| @Test | ||
| void create() { | ||
| LottoPurChase lottoPurChase = new LottoPurChase(14000, 11, 3); | ||
|
|
||
| Assertions.assertThat(lottoPurChase.getMoney()).isEqualTo(new Money(14000)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,31 +3,46 @@ | |||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||||||
|
|
||||||
| public class LottoTest { | ||||||
|
|
||||||
| @Test | ||||||
| void 로또_개수_구하기() { | ||||||
| Lotto lotto = new Lotto(1,2,3,4,5,6); | ||||||
| Lotto lotto = new Lotto(1, 2, 3, 4, 5, 6); | ||||||
|
|
||||||
| assertThat(lotto.countMatchedNumbers( | ||||||
| new Lotto(1,2,3,11,22,33) | ||||||
| new Lotto(1, 2, 3, 11, 22, 33) | ||||||
| )).isEqualTo(3); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void 포함된_숫자인지() { | ||||||
| Lotto lotto = new Lotto(1,2,3,4,5,6); | ||||||
| Lotto lotto = new Lotto(1, 2, 3, 4, 5, 6); | ||||||
|
|
||||||
| assertThat(lotto.contains(LottoNumber.valueOf(1))).isTrue(); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| void 로또_스트링으로_받기() { | ||||||
| Lotto lotto = new Lotto("1","2","3","4","5","6"); | ||||||
| Lotto lotto = new Lotto("1", "2", "3", "4", "5", "6"); | ||||||
|
||||||
| Lotto lotto = new Lotto("1", "2", "3", "4", "5", "6"); | |
| Lotto lotto = new Lotto("1,2,3,4,5,6"); |
문자열 가변인자보다 위와 같이 구현할 수 있으면 더 좋지 않을까?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
중복 체크를 위해 Set으로 변환하고 있다.
Lotto 필드인 List를 Set로 구현해 보면 어떨까?
Set으로 관리하다 외부에서 이 값을 접근할 때 순서를 보장해야 한다면 정렬해서 반환하는 것은 어떨까?