Skip to content

Step3 #1115

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

Merged
merged 25 commits into from
Dec 4, 2024
Merged

Step3 #1115

merged 25 commits into from
Dec 4, 2024

Conversation

devtaebong
Copy link

안녕하세요! 리뷰 잘 부탁드립니다 🙇‍♂️

Copy link

@Flamme1004K Flamme1004K left a comment

Choose a reason for hiding this comment

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

안녕하세요!

3단계 미션 매우 잘 해주셨어요! 코멘트 남겼는데 4단계 미션에서 충분히 반영 가능해 보여서 바로 머지하도록 하겠습니다.

4단계 미션 화이팅입니다!

Comment on lines +1 to +10
# 🚀 3단계 - 로또(2등)

## 기능 요구사항

- 2등을 위해 추가 번호를 하나 더 추첨한다.
- 당첨 통계에 2등도 추가해야 한다.

- [ ] 보너스볼을 입력받는다. (`InputView.kt`)
- [ ] 보너스볼과 당첨번호를 비교해서 로또 등수를 계산한다. (`Match.kt`)
- [ ] 보너스볼 일치 여부(2등)을 통계에 추가한다. (`Statistics.kt`)

Choose a reason for hiding this comment

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

기능 요구사항 잘 작성해주셨어요!

단, 완성 된 기능에 대해서는 체크해주면 더욱 좋겠죠~?

private val amount: Int,
private val lottoNumberListGenerator: LottoNumberListGenerator,
) {
fun purchaseLotto(): List<Lotto> {

Choose a reason for hiding this comment

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

프로그래밍 요구 사항에 일급 컬렉션 사용이 있어요. List를 일급 컬렉션으로 표현해 볼까요?

Comment on lines +8 to 12
init {
require(lottoNumbers.size == REQUIRED_LOTTO_SIZE) {
ERROR_WRONG_NUMBER_COUNT
}
}

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 +16
val lottoNumbers: Set<LottoNumber> = lottoNumbers
val winningLottoNumbers: Set<LottoNumber> = winningLotto.lottoNumbers

Choose a reason for hiding this comment

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

Suggested change
val lottoNumbers: Set<LottoNumber> = lottoNumbers
val winningLottoNumbers: Set<LottoNumber> = winningLotto.lottoNumbers
val lottoNumbers = lottoNumbers
val winningLottoNumbers = winningLotto.lottoNumbers

타입에 대한 부분은 생략해줘도 좋아보여요~ 코틀린의 장점은 타입 추론이 가능하다는 부분이에요. 타입 추론이 있기에 더욱더 명확한 변수 명이 나온다고 생각해요. 명확한 변수 명이 나오면 타입을 어느정도 추론할 수 있다고 봅니다. 그리고 IDE에서 타입을 다 알려주잖아요? ㅎㅎ

Comment on lines 7 to +15
value class LottoNumber(val number: Int) {
companion object {
private const val MINIMUM_NUMBER = 1
private const val MAXIMUM_NUMBER = 45
private const val CANNOT_CREATE_LOTTO_NUMBER_MESSAGE = "Lotto number must be between %s and %s."

private val NUMBERS: Map<Int, LottoNumber> = (MINIMUM_NUMBER..MAXIMUM_NUMBER).associateWith { LottoNumber(it) }

fun from(number: Int): LottoNumber {
return NUMBERS[number] ?: throw IllegalArgumentException(
CANNOT_CREATE_LOTTO_NUMBER_MESSAGE.format(MINIMUM_NUMBER, MAXIMUM_NUMBER),
)
init {
require(number in MINIMUM_NUMBER..MAXIMUM_NUMBER) {
CANNOT_CREATE_LOTTO_NUMBER_MESSAGE.format(MINIMUM_NUMBER, MAXIMUM_NUMBER)
}
}

override fun toString(): String {
return number.toString()
companion object {
private const val CANNOT_CREATE_LOTTO_NUMBER_MESSAGE = "Lotto number must be between %s and %s."

Choose a reason for hiding this comment

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

너무 깔끔해졌네요!

Comment on lines +4 to +11
FIRST(6, 2_000_000_000L),
SECOND(5, 30_000_000L),
THIRD(5, 1_500_000L),
FOURTH(4, 50_000L),
FIFTH(3, 5_000L),
NONE(0, 0L),
;

Choose a reason for hiding this comment

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

enum 사용 잘하셨어요!

Comment on lines +5 to +20
if (matchCount == 6) {
return LottoRank.FIRST
}

private fun rank(matchCount: Int): Int {
return when (matchCount) {
MATCH_COUNT_SIX -> FIRST_RANK
MATCH_COUNT_FIVE -> THIRD_RANK
MATCH_COUNT_FOUR -> FOURTH_RANK
MATCH_COUNT_THREE -> FIFTH_RANK
else -> NO_RANK
}
if (matchCount == 5 && isMatchedBonusBall) {
return LottoRank.SECOND
}
if (matchCount == 5) {
return LottoRank.THIRD
}
if (matchCount == 4) {
return LottoRank.FOURTH
}
if (matchCount == 3) {
return LottoRank.FIFTH
}
return LottoRank.NONE

Choose a reason for hiding this comment

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

if문을 지워볼까요?

Comment on lines +7 to +18
val initialRanks =
LottoRank.entries
.filter { it.matchCount in MINIMUM_MATCH_COUNT..MAXIMUM_MATCH_COUNT }
.associateWith { 0 }

val actualRanks =
lottos.map { winningLotto.getUserRank(it) }
.filter { it.matchCount in MINIMUM_MATCH_COUNT..MAXIMUM_MATCH_COUNT }
.groupingBy { it }
.eachCount()

return initialRanks + actualRanks

Choose a reason for hiding this comment

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

없는 Rank에 대해서는 0으로 나타내주기 위하여 initailRanks를 만든 것이지요?

Copy link
Author

Choose a reason for hiding this comment

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

넵 맞습니다 🙇‍♂️🙇‍♂️🙇‍♂️

amount: Int,
): Double {
return statisticsList.sumOf { it.earnings() }.toDouble() / amount
fun getProfitStatus(earningRatio: Double): String =

Choose a reason for hiding this comment

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

ProfitStatus를 String이 아닌 enum으로 만들어주면 어떨까요?

그러면, 서버의 도메인 로직과 view에 대한 로직을 분리할 수 있어보여요!

import io.kotest.matchers.shouldBe
import lotto.strategy.WinningLottoNumberListGenerator
import lotto.stretagy.LottoNumberListGenerator

class LottoTest : DescribeSpec({

Choose a reason for hiding this comment

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

크~ 테스트 코드가 점점 더 단단해지고 있네요!

@Flamme1004K Flamme1004K merged commit f26ad6b into next-step:devtaebong Dec 4, 2024
@Flamme1004K
Copy link

commit 매우 잘 해주셨어요! 굳굳

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.

2 participants