Skip to content
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

[step4] 로또(수동) #1086

Open
wants to merge 38 commits into
base: pkch93
Choose a base branch
from
Open

[step4] 로또(수동) #1086

wants to merge 38 commits into from

Conversation

pkch93
Copy link

@pkch93 pkch93 commented Nov 26, 2024

로또 미션 4단계 로또(수동) 구현해서 MR 올립니다.

이전에 남겨주신 부분 반영한건 코멘트로 남길께요 :)

- Exception 문구에 정보 추가
- PositiveNumber 정의
- 입력 식 파싱 로직 간소화
- Reward의 당첨 정책 함수로 반영
THIRD(1_500_000, 5, { matchingNumberCount, _ -> matchingNumberCount == 5 }),
FOURTH(50_000, 4, { matchingNumberCount, _ -> matchingNumberCount == 4 }),
FIFTH(5_000, 3, { matchingNumberCount, _ -> matchingNumberCount == 3 }),
NONE(0, 0, { matchingNumberCount, _ -> matchingNumberCount < 3 })
Copy link
Author

Choose a reason for hiding this comment

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

#1072 (comment)

저도 needMatchBonus 부분이 꺼림찍하긴 했는데 이 구현이 좀더 나은거 같네요 :)

인터페이스 정의할 거 없이 함수로 정의해도 될거 같아서 위와 같이 반영했습니다

Copy link

Choose a reason for hiding this comment

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

👍

fun match(lotto: Lotto): Reward {
val matchingNumberCount = this.lotto
.numbers
.count { lotto.numbers.contains(it) }
.count { it in lotto.numbers }
Copy link
Author

Choose a reason for hiding this comment

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

#1072 (comment)

in으로 표현하는게 더 읽기 편해서 위와 같이 수정했어요

@pci2676
Copy link

pci2676 commented Nov 27, 2024

제가 저번 리뷰에서 참고차 알려드린다는게 누락한 부분이 있는데요

BoughtLotto에서 EnumMap으로 init하는 부분을 kotlin에서 제공하는 함수를 이용하면 여러가지 방법으로 표현해볼 수 있습니다.

ex.

return Reward.entries
            .associateWith { 0 }
            .toMap(EnumMap(Reward::class.java))

Copy link

@pci2676 pci2676 left a comment

Choose a reason for hiding this comment

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

조금 개선해보면 좋을 부분에 리뷰를 남겨두었으니 확인해주세요~

THIRD(1_500_000, 5, { matchingNumberCount, _ -> matchingNumberCount == 5 }),
FOURTH(50_000, 4, { matchingNumberCount, _ -> matchingNumberCount == 4 }),
FIFTH(5_000, 3, { matchingNumberCount, _ -> matchingNumberCount == 3 }),
NONE(0, 0, { matchingNumberCount, _ -> matchingNumberCount < 3 })
Copy link

Choose a reason for hiding this comment

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

👍

Comment on lines +50 to +57
val manualLottos = inputManualLottoNumbers(lottoCost)

val autoLottoAmount = lottoCost.autoLottoAmount
val autoLottos = (1..autoLottoAmount).map { Lotto.auto() }

val generatedLottos = manualLottos + autoLottos
printBoughtLottos(lottoCost, generatedLottos)
return generatedLottos
Copy link

Choose a reason for hiding this comment

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

이러한 부분은 view에서 구현하기 적합해 보이지 않는것 같습니다.

view의 종류가 늘어나면 종류가 늘어남과 동시에 위와 같이 생성하는 로직 또한 계속해서 늘어나지 않을까요?

로또 애플리케이션의 중요한 정책으로 보이는데 domain 영역에서 구현해보는게 어떨까요?

@@ -1,6 +1,7 @@
package lotto

class Lotto(
class Lotto
Copy link

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.

2 participants