Skip to content

Conversation

@csbsjy
Copy link

@csbsjy csbsjy commented May 26, 2020

image

@csbsjy csbsjy requested review from Gobukgol, NDjust and pci2676 May 26, 2020 08:27
Comment on lines 9 to 18
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;
}
Copy link
Member

Choose a reason for hiding this comment

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

저는 개인적으로 if 문에다가 조건을 전부 쓰고,
if부터 throw까지 메소드로 빼는게 더 깔끔한거같아요!
조건이 읽히기 쉽다고 생각해서 괜찮다고 봅니다

Copy link
Author

Choose a reason for hiding this comment

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

가끔은 if문이 조금 더 판단하기 쉽다고 생각했는데 이 경우는 딱히 그래보이지 않네용 ㅎㅅㅎ 반영했습니다!

return new Money(totalMoney);
}

public static LottoPrize findByMathCount(int matchCount, boolean matchBonus) {
Copy link
Member

Choose a reason for hiding this comment

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

Match의 오타..인가요?
아니라면 의미가 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

오타입니다 !!

Comment on lines 32 to 46
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;
}
Copy link
Member

Choose a reason for hiding this comment

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

아 요런방법이...
저는 2등이면 2등던져주고 2등 제외한 List를 새로 만들어서 했는데 이게더 좋아보이네요 ㅠㅠ

Copy link

Choose a reason for hiding this comment

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

matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!

Comment on lines 52 to 55
public int getHitCount() {
return hitCount;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이건 안쓰는메소드라 없애도 될거같아요

}
}

public LottoPrize calculateLottoPrize(WinningTicket winningTicket) {
Copy link
Member

Choose a reason for hiding this comment

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

image

양방향 의존성이 발생해 버렸지 뭐야..!

Copy link
Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋ 나 안그래도 이거 질문남겼어 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 해결하겠읍니다 ,,!

Comment on lines 15 to 24
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;
}
Copy link
Member

Choose a reason for hiding this comment

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

LottoTicket이 들고 있는 Integer에 대해 개별적으로 검증해야 할 로직이 있다는건
Integer가 하나의 객체로 분리할 수 있는 신호인거 같아
VO로 분리해보는거 어때?

Comment on lines 50 to 53
public String toString() {
List<Integer> sortedLottoNumbers = new ArrayList<>(lottoNumbers);
Collections.sort(sortedLottoNumbers);
return String.valueOf(sortedLottoNumbers);
Copy link
Member

Choose a reason for hiding this comment

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

헉 나는 toString의 본래 용도대로 사용되는게 아닌거같아 보여

Copy link
Author

Choose a reason for hiding this comment

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

:( 마쟈요 동의합니다 ,,


public double getRateOfProfit(final Money spentMoney) {
Money totalProfit = LottoPrize.calculateTotalReword(lottoStatistics);
return (double) totalProfit.getValue() / spentMoney.getValue() * PERCENTAGE;
Copy link
Member

Choose a reason for hiding this comment

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

이 로직 Money 쪽에서 해줄수 있지않을까?

Comment on lines 6 to 8
public Money(long value) {
this.value = value;
}
Copy link
Member

Choose a reason for hiding this comment

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

0원으로 게임 진행이 가능해 ㅎㅎ
vo 로 쓸수 있는 방어로직이 부족한거 같아

Copy link
Author

Choose a reason for hiding this comment

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

Money는 도메인에 종속된 vo가 아닌데 0원에 대한 방어로직을 Money에서 추가해줘야하나?.? 0원을 넣으면 하나도 못사고 끝나는걸로 괜찮지않을까 생각했어 !!

Copy link
Member

Choose a reason for hiding this comment

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

아하 그러면 마이너스 금액!!

Copy link
Author

Choose a reason for hiding this comment

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

사실 그것도생각해봤는데 -1000원도 뭔가 돈으로 칠라면 칠수있을거같아서 ,,

Copy link
Member

Choose a reason for hiding this comment

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

헉ㅋㅋ
근데 살수 없는 금액인데 당첨번호를 확인하러 가는거 이상하지 않아..??
나는 흐름이 끊겨야 된다고 생각했거든...

Copy link
Author

Choose a reason for hiding this comment

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

마쟈 구럼 차라리 LottoStore에 검증로직을 추가하는건 이상한가 ,,? 0원으로는 살수없습니다 !!

Copy link
Member

Choose a reason for hiding this comment

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

상태와 상태에 관련된 행동이 한곳에 있어야 응집도가 올라간다고 하잖아??
그렇게되면 응집도가 떨어지게되는거같아..!

Copy link
Member

Choose a reason for hiding this comment

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

흠 지금 코드에서 그렇게하면 while 돌릴때 문제가 발생할 수 있겠넹

Comment on lines 14 to 33
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);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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);
}

이넘 이렇게 넣을수 있엉

csbsjy added 3 commits June 4, 2020 20:36
# 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
Comment on lines 41 to 44
return Arrays.stream(winningNumbers.split(LOTTO_NUMBER_DELIMITER))
.map(winningNumber -> Integer.valueOf(winningNumber.trim()))
.map(LottoNumber::of)
.collect(Collectors.toSet());
Copy link

Choose a reason for hiding this comment

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

이부분 ManualLottoNumbers 쪽에도 있는데 중복 제거하는 방법이 있지않을까??
당첨 번호랑 , 수동 로또도 LottoTicket으로 관리하니까 이 부분에서 중복 제거할 수 있는 방법이 있을거같아!



public static void printLottoTicketNumbers(LottoTickets lottoTickets) {
System.out.println(lottoTickets.count() + "개를 구매했습니다.");
Copy link

Choose a reason for hiding this comment

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

우리 요구사항은 수동 개수랑 자동 개수도 출력하는 거니까 맞추는게 좋을것같아!

Copy link
Author

Choose a reason for hiding this comment

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

로또티켓에 상태로 수동자동 여부를 넣을지 별도의 컬렉션으로 구분할지 고민중 ㅠㅠ

this.manualLottoNumbers = Arrays.stream(manualLottoNumbers.split(MANUAL_LOTTO_NUMBERS_DELIMITER))
.map(number -> Integer.parseInt(number.trim()))
.map(LottoNumber::of)
.collect(toSet());
Copy link

Choose a reason for hiding this comment

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

image

toSet하는 과정에서 정렬이 안돼서 LottoNumber에 Comparable 구현하구 treeSet 사용하면 될꺼야!

Copy link
Author

Choose a reason for hiding this comment

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

이민형 천재

assertThatThrownBy(() -> new LottoTicket(numbers))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("로또티켓은 6개의 로또숫자로 이루어져야합니다.");
}
Copy link

Choose a reason for hiding this comment

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

로또 번호 중복도 같은 로직 탈것같은데 그래도 명시적으로 써주면 좋을것 같아!

MISS(0, Money.of(0));

private final int matchCount;
private final Money reward;
Copy link

Choose a reason for hiding this comment

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

Money로 감싸는거 굳인듯!

Copy link

Choose a reason for hiding this comment

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

오우 짱이네요! 하나 배워갑니다.

@csbsjy csbsjy changed the title 로또(자동) 로또(순서보장) Jun 11, 2020
Comment on lines 25 to 31
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;

Choose a reason for hiding this comment

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

인덴트 규칙! stream 으로 해결할 수 있지않을까?

Copy link
Author

Choose a reason for hiding this comment

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

헉스 나중에고쳐야지~하고 넘겼다 떙쿄 !!

Copy link
Author

Choose a reason for hiding this comment

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

    public int getMatchCount(LottoTicket lottoTicket) {
        return Math.toIntExact(IntStream.range(0, COUNT_OF_LOTTO_NUMBER)
                .filter(index -> isSameLottoNumber(index, lottoTicket.lottoNumbers.get(index)))
                .count());
    }

지금 이렇게밖에 생각이안나는데 더 좋은방법있을깡? ㅠㅠ

Choose a reason for hiding this comment

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

나도 당장은 이런식으로 했어 ㅋㅋㅋ

class LottoPrizeTest {

@DisplayName("번호일치 갯수에 따른 LottoPrize를 반환한다")
@CsvSource({"3,flase,FIFTH", "5, false,THIRD", "5,true,SECOND",

Choose a reason for hiding this comment

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

여기 flase 로 오타있어서 제대로 들어오기 보단 false, true 가 둘다 아니여서 false로 들어가는거 같아.
image
ture 로 해도.
image
false 로 들어오니까 조심하는게 좋을 것 같아!

Copy link
Author

Choose a reason for hiding this comment

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

미쳐따 떙쿜ㅋㅋ

Comment on lines 32 to 46
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;
}
Copy link

Choose a reason for hiding this comment

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

matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!

public class BonusNumber {
private final int number;

public BonusNumber(int number) {
Copy link

Choose a reason for hiding this comment

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

저도 찬인님 말씀대로 BonusNumber와 WinningTicket 모두 number(integer)값에 대한 유효성 검사가 들어가서 한번 더 객체로 감싸서 하면 좋다고 생각합니다! ㅎㅎ

Copy link
Author

Choose a reason for hiding this comment

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

위에꺼는답글이 안달아지내용!

matchBonus 변수 자체가 보너스 번호 유무를 넘겨주는 건데, matchCount == THIRD.hitCount && matchBonus말고 한번 더 findByBonus로 빼신 이유가 있을까요??
개인적으로 메소드 없는게 더 파악이 잘되는 느낌이라서요!

if(matchCount == THIRD.hitCount && matchBonus){
       return SECOND;
}
if(matchCount == THIRD.hitCount && !matchBonus){
       return THRID;
}

보다는 위의 방식이 더 가독성있어보인다고 생각했어요!

Copy link
Author

Choose a reason for hiding this comment

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

BonusNumber는 지금은 없는 클래스예요! LottoNumber로 대체하고있어용

return new LottoTickets(lottoTickets);
}

private boolean isEnoughChange(Money currentChange) {
Copy link

Choose a reason for hiding this comment

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

Money에서 isEnougToBuy랑 같은 행위를 하는데, 한번 더 메소드로 빼신 이유가 있으신가요?! 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

이것도 지금 없어짐 메서드일거예여!

return manualLottoTickets.combine(autoLottoTickets);
}

private LottoTickets buy(final Money budget) {
Copy link

Choose a reason for hiding this comment

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

buyAutoTickets라고 메소드 네이밍 바꾸는 건 어떨까요?? 처음에 약간 buy안에 buy메소드가 있어서 약간 오잉 재귀? 햇어요!

Copy link
Author

Choose a reason for hiding this comment

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

재귀보다는 오버로딩을 활용한건데 요즘 오버로딩을 자제하려고 노력하고있어요 ㅋㅋㅋ 나단님처럼 재귀로파악할 소지도 있으니까용!

MISS(0, Money.of(0));

private final int matchCount;
private final Money reward;
Copy link

Choose a reason for hiding this comment

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

오우 짱이네요! 하나 배워갑니다.

}

public static LottoNumber of(final int value) {
return CACHE.computeIfAbsent(value, LottoNumber::new);
Copy link

Choose a reason for hiding this comment

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

CACHE.computeIfAbsent(value, LottoNumber::new);

그냥 LottoNumber로 변환하는 것보다 이렇게 사용하면 이점이 있나요?? 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

첫번째 파라미터를 키로하는 Value가 Map에 없는경우 Map에 두번째 Functional에서 반환하는 인스턴스를 Map에 추가하고 반환해줘요!
null체크와 put을 동시에할 수 있는 유용한 메서드입니다!

Copy link

Choose a reason for hiding this comment

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

와우 감사합니다!!

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;
Copy link
Member

Choose a reason for hiding this comment

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

이거 사실 LottoTicket이랑 AutoGenerator에서만 사용하는데 Lottoticket의 공개 상수로만 둬도 문제가 없을 것 같아
어차피 Auto쪽에서 LottoTicket을 알고 있거든

Copy link
Member

Choose a reason for hiding this comment

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

COUNT_OF_LOTTO_NUMBER 이것만!

Copy link
Author

Choose a reason for hiding this comment

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

오키오키! 상수클래스 없애벌여ㅑ지`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants