-
Notifications
You must be signed in to change notification settings - Fork 355
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
Step3 로또(2등) #1089
base: duhanmo
Are you sure you want to change the base?
Step3 로또(2등) #1089
Conversation
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.
안녕하세요 두한님 👋
이번 단계도 너무 잘 구현해주셨네요!
몇 가지 코멘트 남겼으니 확인부탁드려요.
@JvmInline | ||
value class LottoNumber(val number: Int) { | ||
init { | ||
require(number in LOTTO_NUMBER_RANGE) { "로또 번호는 $LOTTO_MIN_NUMBER 부터 $LOTTO_MAX_NUMBER 사이어야 합니다" } | ||
} |
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.
요것도 값 객체로 감싸주셨군요 👍
|
||
init { | ||
require(numbers.size == LOTTO_NUMBER_COUNT) { "로또 번호는 $LOTTO_NUMBER_COUNT 개이어야 합니다" } | ||
this.numbers = numbers.sortedBy { it.number }.toSet() |
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.
LottoNumber가 Comparable을 구현해도 좋을 것 같습니다!
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.
네! 말씀하신대로 구현해볼게요😄
} | ||
|
||
fun containsNumber(other: LottoNumber): Boolean { | ||
return numbers.contains(other) |
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.
in
키워드가 conatins에 대응하는 operator 처럼 작동하기 때문에 other in numbers
처럼 사용이 가능해요. 취향껏 사용해주시면 되겠습니다.
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.
네! 좋은 키워드 알려주셔서 감사해요😊 반영하도록 하겠습니다!👍
SECOND(2, 5, Money(30_000_000), { matchedCount, matchBonus -> matchedCount == SECOND.matchedCount && matchBonus }), | ||
THIRD(3, 5, Money(1_500_000), { matchedCount, matchBonus -> matchedCount == THIRD.matchedCount && !matchBonus }), |
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.
2,3등 조건도 굉장히 꼼꼼하게 구현해주셨군요 💯
남길 코멘트가 별로 없어요... 😭
THIRD(3, 5, Money(1_500_000), { matchedCount, matchBonus -> matchedCount == THIRD.matchedCount && !matchBonus }), | ||
FOURTH(4, 4, Money(50_000), { matchedCount, _ -> matchedCount == FOURTH.matchedCount }), | ||
FIFTH(5, 3, Money(5_000), { matchedCount, _ -> matchedCount == FIFTH.matchedCount }), | ||
MISS(6, 0, Money(0), { matchedCount, _ -> matchedCount in MISS.matchedCount..<FIFTH.matchedCount }), |
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.
rangeUntil은 처음본다 했더니 1.9에 추가된 기능이군요! 하나 배워갑니다.
(a until b) 처럼 사용할 수도 있어요!
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.
🙂a until b 처럼도 사용할 수 있군요! 좋은 정보 감사해요
val rankValue: Int, | ||
val matchedCount: Int, | ||
val money: Money, | ||
private val matched: (Int, Boolean) -> Boolean, |
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.
kotiln에서 null은 "값이 없음"을 나타낼 때 유용하게 쓰일 수 있습니다.
이를 활용하여 matched를 각 enum의 값들이 갖고 있는 게 아닌 enum의 메서드 형태로 빼면 어떨까요?
val matchBonus: Boolean?
...
fun matched(Int a, Boolean b): Boolean { }
물론 여기도 취향의 영역이긴 합니다.
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.
네! matchBonus를 nullable하게 추출하고 말씀하신 메서드형태로 추출해볼게요 좋은 의견 감사해요 😊
val matchedCount = winningLotto.countMatchedNumber(lotto) | ||
val matchBonus = winningLotto.matchBonus(lotto) |
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.
Winninglotto로 감싸둔 덕분에 깔끔하네요 👍
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.
이전 단계에서 피드백 주신대로 해보았는데, 이번 단계 구현할 때 조금 더 깔끔해짐을 느꼈어요!
좋은 피드백 감사합니다🙇♂️🙂
fun create(): LottoNumber { | ||
return LottoNumber(LOTTO_NUMBER_RANGE.random()) | ||
} |
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.
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.
네! 좋은 의견감사해요😊
다시 확인해보니 해당 메서드는 테스트에서만 사용하고 있었네요🥲
해당 메서드를 제거하고 테스트하고자 했던 항목은 다른방식으로 작성해볼게요! 😀
안녕하세요 범준님🙂 그럼 리뷰 잘부탁드려요🙇♂️ |
안녕하세요 범준님! 🙂
step2 에서 남긴 피드백 반영함께 해보았어요.
그럼 리뷰 잘부탁드려요🙇♂️