Conversation
| public BonusNumber(int number) { | ||
| if (isValidNumber(number)) { | ||
| throw new IllegalArgumentException("보너스번호는 1이상 45이하여야합니다"); | ||
| } | ||
| this.number = number; | ||
| } | ||
|
|
||
| private boolean isValidNumber(int number) { | ||
| return number < NUMBER_BEGIN_BOUND || number > NUMBER_END_BOUND; | ||
| } |
There was a problem hiding this comment.
저는 개인적으로 if 문에다가 조건을 전부 쓰고,
if부터 throw까지 메소드로 빼는게 더 깔끔한거같아요!
조건이 읽히기 쉽다고 생각해서 괜찮다고 봅니다
There was a problem hiding this comment.
가끔은 if문이 조금 더 판단하기 쉽다고 생각했는데 이 경우는 딱히 그래보이지 않네용 ㅎㅅㅎ 반영했습니다!
| return new Money(totalMoney); | ||
| } | ||
|
|
||
| public static LottoPrize findByMathCount(int matchCount, boolean matchBonus) { |
There was a problem hiding this comment.
Match의 오타..인가요?
아니라면 의미가 궁금합니다!
| if (matchCount == THIRD.hitCount) { | ||
| return findByBonus(matchBonus); | ||
| } | ||
| return Arrays.stream(LottoPrize.values()) | ||
| .filter(lottoPrize -> lottoPrize.hitCount == matchCount) | ||
| .findAny() | ||
| .orElse(MISS); | ||
| } | ||
|
|
||
| private static LottoPrize findByBonus(boolean matchBonus) { | ||
| if (matchBonus) { | ||
| return SECOND; | ||
| } | ||
| return THIRD; | ||
| } |
There was a problem hiding this comment.
아 요런방법이...
저는 2등이면 2등던져주고 2등 제외한 List를 새로 만들어서 했는데 이게더 좋아보이네요 ㅠㅠ
There was a problem hiding this comment.
matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!
| public int getHitCount() { | ||
| return hitCount; | ||
| } | ||
| } |
| } | ||
| } | ||
|
|
||
| public LottoPrize calculateLottoPrize(WinningTicket winningTicket) { |
There was a problem hiding this comment.
ㅋㅋㅋㅋㅋㅋㅋ 나 안그래도 이거 질문남겼어 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 해결하겠읍니다 ,,!
| private final Set<Integer> lottoNumbers; | ||
|
|
||
| public LottoTicket(Set<Integer> lottoNumbers) { | ||
| validate(lottoNumbers); | ||
| this.lottoNumbers = lottoNumbers; | ||
| } | ||
|
|
||
| private static boolean isValidNumber(Integer number) { | ||
| return number >= NUMBER_BEGIN_BOUND && number <= NUMBER_END_BOUND; | ||
| } |
There was a problem hiding this comment.
LottoTicket이 들고 있는 Integer에 대해 개별적으로 검증해야 할 로직이 있다는건
Integer가 하나의 객체로 분리할 수 있는 신호인거 같아
VO로 분리해보는거 어때?
| public String toString() { | ||
| List<Integer> sortedLottoNumbers = new ArrayList<>(lottoNumbers); | ||
| Collections.sort(sortedLottoNumbers); | ||
| return String.valueOf(sortedLottoNumbers); |
There was a problem hiding this comment.
헉 나는 toString의 본래 용도대로 사용되는게 아닌거같아 보여
|
|
||
| public double getRateOfProfit(final Money spentMoney) { | ||
| Money totalProfit = LottoPrize.calculateTotalReword(lottoStatistics); | ||
| return (double) totalProfit.getValue() / spentMoney.getValue() * PERCENTAGE; |
| public Money(long value) { | ||
| this.value = value; | ||
| } |
There was a problem hiding this comment.
0원으로 게임 진행이 가능해 ㅎㅎ
vo 로 쓸수 있는 방어로직이 부족한거 같아
There was a problem hiding this comment.
Money는 도메인에 종속된 vo가 아닌데 0원에 대한 방어로직을 Money에서 추가해줘야하나?.? 0원을 넣으면 하나도 못사고 끝나는걸로 괜찮지않을까 생각했어 !!
There was a problem hiding this comment.
사실 그것도생각해봤는데 -1000원도 뭔가 돈으로 칠라면 칠수있을거같아서 ,,
There was a problem hiding this comment.
헉ㅋㅋ
근데 살수 없는 금액인데 당첨번호를 확인하러 가는거 이상하지 않아..??
나는 흐름이 끊겨야 된다고 생각했거든...
There was a problem hiding this comment.
마쟈 구럼 차라리 LottoStore에 검증로직을 추가하는건 이상한가 ,,? 0원으로는 살수없습니다 !!
There was a problem hiding this comment.
상태와 상태에 관련된 행동이 한곳에 있어야 응집도가 올라간다고 하잖아??
그렇게되면 응집도가 떨어지게되는거같아..!
There was a problem hiding this comment.
흠 지금 코드에서 그렇게하면 while 돌릴때 문제가 발생할 수 있겠넹
| static Stream<Arguments> lottoPrizes() { | ||
| return Stream.of( | ||
| Arguments.of(3, false, LottoPrize.FIFTH), | ||
| Arguments.of(5, false, LottoPrize.THIRD), | ||
| Arguments.of(5, true, LottoPrize.SECOND), | ||
| Arguments.of(6, false, LottoPrize.FIRST), | ||
| Arguments.of(2, false, LottoPrize.MISS) | ||
| ); | ||
| } | ||
|
|
||
| @DisplayName("번호일치 갯수에 따른 LottoPrize를 반환한다") | ||
| @MethodSource("lottoPrizes") | ||
| @ParameterizedTest | ||
| void findLottoPrize(int matchCount, boolean matchBonus, LottoPrize expectedLottoPrize) { | ||
| //when | ||
| LottoPrize byMathCount = LottoPrize.findByMathCount(matchCount, matchBonus); | ||
|
|
||
| //then | ||
| assertThat(byMathCount).isEqualTo(expectedLottoPrize); | ||
| } |
There was a problem hiding this comment.
| static Stream<Arguments> lottoPrizes() { | |
| return Stream.of( | |
| Arguments.of(3, false, LottoPrize.FIFTH), | |
| Arguments.of(5, false, LottoPrize.THIRD), | |
| Arguments.of(5, true, LottoPrize.SECOND), | |
| Arguments.of(6, false, LottoPrize.FIRST), | |
| Arguments.of(2, false, LottoPrize.MISS) | |
| ); | |
| } | |
| @DisplayName("번호일치 갯수에 따른 LottoPrize를 반환한다") | |
| @MethodSource("lottoPrizes") | |
| @ParameterizedTest | |
| void findLottoPrize(int matchCount, boolean matchBonus, LottoPrize expectedLottoPrize) { | |
| //when | |
| LottoPrize byMathCount = LottoPrize.findByMathCount(matchCount, matchBonus); | |
| //then | |
| assertThat(byMathCount).isEqualTo(expectedLottoPrize); | |
| } | |
| @DisplayName("번호일치 갯수에 따른 LottoPrize를 반환한다") | |
| @ParameterizedTest | |
| @CsvSource(value = {"3,false,FIFTH","5,false,THIRD","5,true,SECOND"}) | |
| void findLottoPrize(int matchCount, boolean matchBonus, LottoPrize expectedLottoPrize) { | |
| //when | |
| LottoPrize byMathCount = LottoPrize.findByMathCount(matchCount, matchBonus); | |
| //then | |
| assertThat(byMathCount).isEqualTo(expectedLottoPrize); | |
| } | |
이넘 이렇게 넣을수 있엉
# Conflicts: # src/main/java/com/javabom/lotto/LottoApplication.java # src/main/java/com/javabom/lotto/view/InputView.java # src/main/java/com/javabom/lotto/view/OutputView.java # src/test/java/com/javabom/lotto/domain/LottoTicketTest.java # src/test/java/com/javabom/lotto/domain/LottoTicketsTest.java
| return Arrays.stream(winningNumbers.split(LOTTO_NUMBER_DELIMITER)) | ||
| .map(winningNumber -> Integer.valueOf(winningNumber.trim())) | ||
| .map(LottoNumber::of) | ||
| .collect(Collectors.toSet()); |
There was a problem hiding this comment.
이부분 ManualLottoNumbers 쪽에도 있는데 중복 제거하는 방법이 있지않을까??
당첨 번호랑 , 수동 로또도 LottoTicket으로 관리하니까 이 부분에서 중복 제거할 수 있는 방법이 있을거같아!
|
|
||
|
|
||
| public static void printLottoTicketNumbers(LottoTickets lottoTickets) { | ||
| System.out.println(lottoTickets.count() + "개를 구매했습니다."); |
There was a problem hiding this comment.
우리 요구사항은 수동 개수랑 자동 개수도 출력하는 거니까 맞추는게 좋을것같아!
There was a problem hiding this comment.
로또티켓에 상태로 수동자동 여부를 넣을지 별도의 컬렉션으로 구분할지 고민중 ㅠㅠ
| this.manualLottoNumbers = Arrays.stream(manualLottoNumbers.split(MANUAL_LOTTO_NUMBERS_DELIMITER)) | ||
| .map(number -> Integer.parseInt(number.trim())) | ||
| .map(LottoNumber::of) | ||
| .collect(toSet()); |
| assertThatThrownBy(() -> new LottoTicket(numbers)) | ||
| .isInstanceOf(IllegalArgumentException.class) | ||
| .hasMessage("로또티켓은 6개의 로또숫자로 이루어져야합니다."); | ||
| } |
There was a problem hiding this comment.
로또 번호 중복도 같은 로직 탈것같은데 그래도 명시적으로 써주면 좋을것 같아!
| MISS(0, Money.of(0)); | ||
|
|
||
| private final int matchCount; | ||
| private final Money reward; |
| int matchCount = 0; | ||
| for (int i = 0; i < COUNT_OF_LOTTO_NUMBER; i++) { | ||
| if (lottoTicket.lottoNumbers.get(i).equals(this.lottoNumbers.get(i))) { | ||
| matchCount++; | ||
| } | ||
| } | ||
| return matchCount; |
There was a problem hiding this comment.
public int getMatchCount(LottoTicket lottoTicket) {
return Math.toIntExact(IntStream.range(0, COUNT_OF_LOTTO_NUMBER)
.filter(index -> isSameLottoNumber(index, lottoTicket.lottoNumbers.get(index)))
.count());
}지금 이렇게밖에 생각이안나는데 더 좋은방법있을깡? ㅠㅠ
| class LottoPrizeTest { | ||
|
|
||
| @DisplayName("번호일치 갯수에 따른 LottoPrize를 반환한다") | ||
| @CsvSource({"3,flase,FIFTH", "5, false,THIRD", "5,true,SECOND", |
| if (matchCount == THIRD.hitCount) { | ||
| return findByBonus(matchBonus); | ||
| } | ||
| return Arrays.stream(LottoPrize.values()) | ||
| .filter(lottoPrize -> lottoPrize.hitCount == matchCount) | ||
| .findAny() | ||
| .orElse(MISS); | ||
| } | ||
|
|
||
| private static LottoPrize findByBonus(boolean matchBonus) { | ||
| if (matchBonus) { | ||
| return SECOND; | ||
| } | ||
| return THIRD; | ||
| } |
There was a problem hiding this comment.
matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!
| public class BonusNumber { | ||
| private final int number; | ||
|
|
||
| public BonusNumber(int number) { |
There was a problem hiding this comment.
저도 찬인님 말씀대로 BonusNumber와 WinningTicket 모두 number(integer)값에 대한 유효성 검사가 들어가서 한번 더 객체로 감싸서 하면 좋다고 생각합니다! ㅎㅎ
There was a problem hiding this comment.
위에꺼는답글이 안달아지내용!
matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!
if(matchCount == THIRD.hitCount && matchBonus){
return SECOND;
}
if(matchCount == THIRD.hitCount && !matchBonus){
return THRID;
}보다는 위의 방식이 더 가독성있어보인다고 생각했어요!
There was a problem hiding this comment.
BonusNumber는 지금은 없는 클래스예요! LottoNumber로 대체하고있어용
| return new LottoTickets(lottoTickets); | ||
| } | ||
|
|
||
| private boolean isEnoughChange(Money currentChange) { |
There was a problem hiding this comment.
Money에서 isEnougToBuy랑 같은 행위를 하는데, 한번 더 메소드로 빼신 이유가 있으신가요?! 궁금합니다!
| return manualLottoTickets.combine(autoLottoTickets); | ||
| } | ||
|
|
||
| private LottoTickets buy(final Money budget) { |
There was a problem hiding this comment.
buyAutoTickets라고 메소드 네이밍 바꾸는 건 어떨까요?? 처음에 약간 buy안에 buy메소드가 있어서 약간 오잉 재귀? 햇어요!
There was a problem hiding this comment.
재귀보다는 오버로딩을 활용한건데 요즘 오버로딩을 자제하려고 노력하고있어요 ㅋㅋㅋ 나단님처럼 재귀로파악할 소지도 있으니까용!
| MISS(0, Money.of(0)); | ||
|
|
||
| private final int matchCount; | ||
| private final Money reward; |
| } | ||
|
|
||
| public static LottoNumber of(final int value) { | ||
| return CACHE.computeIfAbsent(value, LottoNumber::new); |
There was a problem hiding this comment.
CACHE.computeIfAbsent(value, LottoNumber::new);그냥 LottoNumber로 변환하는 것보다 이렇게 사용하면 이점이 있나요?? 궁금합니다!
There was a problem hiding this comment.
첫번째 파라미터를 키로하는 Value가 Map에 없는경우 Map에 두번째 Functional에서 반환하는 인스턴스를 Map에 추가하고 반환해줘요!
null체크와 put을 동시에할 수 있는 유용한 메서드입니다!
| public class LottoGameProperty { | ||
| public static final int LOTTO_NUMBER_BEGIN_BOUND = 1; | ||
| public static final int LOTTO_NUMBER_END_BOUND = 45; | ||
| public static final int COUNT_OF_LOTTO_NUMBER = 6; |
There was a problem hiding this comment.
이거 사실 LottoTicket이랑 AutoGenerator에서만 사용하는데 Lottoticket의 공개 상수로만 둬도 문제가 없을 것 같아
어차피 Auto쪽에서 LottoTicket을 알고 있거든




Uh oh!
There was an error while loading. Please reload this page.