-
Notifications
You must be signed in to change notification settings - Fork 323
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
🚀 2단계 - 로또(자동) #532
base: shinseongsu
Are you sure you want to change the base?
🚀 2단계 - 로또(자동) #532
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.
안녕하세요 성수님! 죄송하시다뇨! 아닙니다 😅 빨리 리뷰 못드린 제가 죄송하지요.
너무 완성도 높게 미션 진행해주셔서 감탄 코멘트만 반복한거 같네요.
사소한 부분 몇가지 코멘트 남겼으니 확인해주시면 바로 approve 하도록 하겠습니다.
나머지 로또 미션도 화이팅입니다! 💪
궁금하신 점 언제든지 코멘트 남겨주세요 🙇♂️
companion object { | ||
const val LOTTO_START_NUMBER = 1 | ||
const val LOTTO_END_NUMBER = 45 | ||
const val LOTTO_NUMBERS_SIZE = 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.
RandomNumberGenerator
내부에서만 사용되는 상수들이라면 private 으로 가려줄 수 있을거 같아요!
override fun generate(): List<Int> { | ||
val range = LOTTO_START_NUMBER..LOTTO_END_NUMBER | ||
val shuffled = range.shuffled() | ||
return shuffled.subList(0, LOTTO_NUMBERS_SIZE).sorted() | ||
} |
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.
1~45 사이 6개 난수 발생로직 깔끔하네요 👍 👍
난수가 잘 발생되는지 테스트 코드 작성이 가능할까요?
(혹시나 테스트 코드 작성에 어려움이 느껴지신다면 코멘트 남겨주세요!)
} | ||
|
||
fun validateNotBlank(string: String) { | ||
require(!string.isBlank()) { "값이 비어 있습니다." } |
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.
isNotBlank()
로도 대체할 수 있겠네요! 👍
private fun String.isNumeric(): Boolean { | ||
return this.toCharArray().all { it in '0'..'9' } | ||
} |
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.
wow 😮 👍
const val INPUT_PAYMENT_GUIDE = "# 구입금액을 입력해주세요." | ||
const val INPUT_LUCKY_NUMBERS_GUIDE = "# 지난 주 당첨 번호를 입력해 주세요." |
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.
역시나 내부에서만 사용된다면 private 으로 😉
class LottoShop( | ||
private val lottoGenerator: LottoGenerator | ||
) { | ||
|
||
fun buy(inputPayment: Int): List<Lotto> { | ||
val lottoCount = calculateLottoCount(inputPayment) | ||
return lottoGenerator.generate(lottoCount) | ||
} | ||
|
||
private fun calculateLottoCount(payment: Int): Int { | ||
return payment / LOTTO_PRICE | ||
} | ||
|
||
companion object { | ||
private const val LOTTO_PRICE = 1000 | ||
} |
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 generate(size: Int): List<Lotto> { | ||
return List(size) { Lotto(numberGenerator.generate()) } | ||
} |
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.
정말정말 깔끔하고 좋으네요 😆
(제 취향이므로 반영 안하셔도 됩니다!) 네이밍을 통해 '1~45 사이의 로또 번호를 발급' 한다는 걸 더 티내기 위해 LottoNumberGenerator
와 같이 조금 더 적나라한 네이밍을 쓰는걸 선호합니다 😄
val luckNumbers = InputView.inputLuckyNumbers() | ||
val statistics = lottoStatisticsService.statistics(luckNumbers, lottoList, inputPayment) |
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.
입력된 당첨 번호가 1~45 사이 숫자가 아닐수도 있겠네요 😄
return NumberUtil.floor(totalRate, EARING_RATE_DECIMAL_PLACE) | ||
} | ||
|
||
companion object { | ||
private const val EARING_RATE_DECIMAL_PLACE = 2 | ||
} |
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.
소숫점 둘째자리까지 '표현'한다는 것은 다른 녀석에게 더 어울리는 책임이겠죠? 😄
winLottoStatisticsResult.forEach { | ||
val hitCount = it.winLottoPrize.hitCount | ||
val prizeMoney = it.winLottoPrize.prizeMoney | ||
val winLottoCount = it.winLottoCount | ||
println("${hitCount}개 일치 (${prizeMoney}원) - ${winLottoCount}개") | ||
} |
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.
와 👍 👍 👍 👍 👍 👍
멘토님 안녕하세요 오랜만에 PR 보내서 죄송합니다.
기능 구현
구현하면서 생각한점
Controller 에서 입력과 출력이 의존되게 구현하였으며, 결과 통계를 class에 담아서 출력하였습니다.