-
Notifications
You must be signed in to change notification settings - Fork 4
Step2 #9
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
base: delf
Are you sure you want to change the base?
Step2 #9
Changes from all commits
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 |
|---|---|---|
|
|
@@ -25,12 +25,12 @@ public enum Rank { | |
| this.winningMoney = winningMoney; | ||
| } | ||
|
|
||
| public static Rank valueOf(int countOfMatch) { | ||
| public static Rank valueOf(int countOfMatch, boolean matchBonus) { | ||
|
Member
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.
|
||
| if (countOfMatch < WINNING_MIN_COUNT) { | ||
| return MISS; | ||
| } | ||
|
|
||
| if (SECOND.matchCount(countOfMatch)) { | ||
| if (SECOND.matchCount(countOfMatch) && matchBonus) { | ||
| return SECOND; | ||
| } | ||
|
|
||
|
|
@@ -61,6 +61,10 @@ public static Map<Rank, Integer> RANK_COUNTER() { | |
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("%d개 일치 (%,d원)", countOfMatch, winningMoney); | ||
| String note = ""; | ||
| if (this == Rank.SECOND) { | ||
|
Member
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. 이 부분을 다른 Object로 리팩토링할 수 없을까요?
Author
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. 저도 출력에 관한 책임을 따로 분리할 계획을 갖고 있었습니다ㅎㅎ 다음 스탭때 구현해보도록 하죠. |
||
| note = ", 보너스볼 일치"; | ||
| } | ||
| return String.format("%d개 일치%s (%,d원)", countOfMatch, note, winningMoney); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package domain.lotto; | ||
|
|
||
| import domain.Rank; | ||
|
|
||
| public class WinningLotto { | ||
| private Lotto lotto; | ||
| private LottoNumber bonusNumber; | ||
|
|
||
| public WinningLotto(Lotto lotto, LottoNumber bonusNumber) { | ||
|
Member
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. WinningLotto와 BonusNumber는 종속적인 관계인가요? |
||
| this.lotto = lotto; | ||
| this.bonusNumber = bonusNumber; | ||
| } | ||
|
|
||
| public Rank match(Lotto userLotto) { | ||
| int matchCount = lotto.getMatchCount(userLotto); | ||
| boolean matchBonus = userLotto.contains(bonusNumber); | ||
| return Rank.valueOf(matchCount, matchBonus); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("%s + %s", lotto , bonusNumber); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package output; | ||
|
|
||
| import domain.Rank; | ||
| import domain.lotto.LottoCollection; | ||
| import domain.LottoStatistics; | ||
|
|
||
|
|
@@ -14,10 +15,15 @@ public static void printLotto(LottoCollection lottoCollection) { | |
| } | ||
|
|
||
| public static void showWinningStatistics(LottoStatistics lottoStatistics) { | ||
| final Rank[] PRINT_ORDER_RANK = {Rank.FIFTH, Rank.FOURTH, Rank.THIRD, Rank.SECOND, Rank.FIRST}; | ||
|
|
||
| System.out.println("당첨 통계" + "\n" + "-------------"); | ||
| lottoStatistics.forEach(rank -> System.out.println( | ||
| /*lottoStatistics.forEach(rank -> System.out.println( | ||
|
Member
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. 불필요한 주석은 제거해주세요 :) |
||
| String.format("- %s %s개", rank, lottoStatistics.getCount(rank))) | ||
| ); | ||
| );*/ | ||
| for(Rank rank : PRINT_ORDER_RANK) { | ||
| System.out.println(String.format("- %s %s개", rank, lottoStatistics.getCount(rank))); | ||
| } | ||
| System.out.println(String.format("\n총 수익률은 %.2f%%입니다.", lottoStatistics.getRor())); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package domain.lotto; | ||
|
|
||
| import domain.Rank; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import static java.util.stream.Collectors.toList; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class WinningLottoTest { | ||
|
|
||
| private final static WinningLotto WINNING_LOTTO = new WinningLotto( | ||
| new Lotto(Arrays.asList(LottoNumber.of(1), LottoNumber.of(2), LottoNumber.of(3), LottoNumber.of(4), LottoNumber.of(5), LottoNumber.of(6))), | ||
| LottoNumber.of(7) | ||
| ); | ||
|
|
||
| @Test | ||
| void noMatch() { | ||
| final Lotto userLotto = generateLotto(8, 9, 10, 11, 12, 13, 14); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.MISS); | ||
|
Member
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. 모든 케이스에 대해 테스트를 작성하는게 의미가 있을까요?
Author
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. 의미있는 경곗값만 테스트하는걸 고려해볼 수 있겠네요 |
||
| } | ||
|
|
||
| @Test | ||
| void matchThree() { | ||
| final Lotto userLotto = generateLotto(1, 2, 3, 11, 12, 13); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.FIFTH); | ||
| } | ||
|
|
||
| @Test | ||
| void matchFour() { | ||
| final Lotto userLotto = generateLotto(1, 2, 3, 4, 12, 13); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.FOURTH); | ||
| } | ||
|
|
||
| @Test | ||
| void matchFive() { | ||
| final Lotto userLotto = generateLotto(1, 2, 3, 4, 5, 13); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.THIRD); | ||
| } | ||
|
|
||
| @Test | ||
| void matchSix() { | ||
| final Lotto userLotto = generateLotto(1, 2, 3, 4, 5, 6); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.FIRST); | ||
| } | ||
|
|
||
| @Test | ||
| void matchFiveAndBonus() { | ||
| final Lotto userLotto = generateLotto(1, 2, 3, 4, 5, 7, 14); | ||
| assertThat(WINNING_LOTTO.match(userLotto)).isEqualTo(Rank.SECOND); | ||
| } | ||
|
|
||
|
|
||
| private Lotto generateLotto(int... lottoNumbers) { | ||
| return new Lotto(Arrays.stream(lottoNumbers).mapToObj(LottoNumber::of).collect(toList())); | ||
| } | ||
|
|
||
| } | ||
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.
Map<Rank, Integer>을 추상화 하는 건 어떨까요?Rank.RANK_COUNTER()안의 로직과 이 메서드의 로직을 책임으로 가질 수 있을 것 같아요.