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

[둘리] 1단계 로또 제출합니다. #17

Merged
merged 36 commits into from
Feb 19, 2023

Conversation

hyemdooly
Copy link

안녕하세요, 리뷰어님! 바쁘신 와중에 코드를 리뷰해주셔서 감사합니다.
열심히 배우겠습니다!

re4rk and others added 29 commits February 14, 2023 15:38
fun outputResult(lottoResult: LottoResult) {
println("\n당첨 통계")
println("---------")
println("3개 일치 (${Rank.FIFTH.winningMoney})원 - ${lottoResult[Rank.FIFTH]}개")
Copy link

@vagabond95 vagabond95 Feb 16, 2023

Choose a reason for hiding this comment

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

require(countOfMatch in LOTTO_COUNT_MIN..LOTTO_COUNT_MAX) { ERROR_COUNT_OF_MATCH_RANGE.format(countOfMatch) }
require(countOfMatch != LOTTO_COUNT_MAX || matchBonus.not()) { ERROR_IMPOSSIBLE_CASE }

return when (countOfMatch) {

Choose a reason for hiding this comment

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

values() 를 활용하면 간결하게 표현이 가능하지 않을까요?

}

fun getRateOfReturn(): Double =
floor(

Choose a reason for hiding this comment

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

각 연산에 대한 부분을 함수로 나누거나 변수로 단계를 나눠주면 가독성이 좀 더 확보될 것 같아요.

const val NUMBER_SIZE = 6
private const val ERROR_NUMBER_SIZE = "로또 번호의 개수는 6개여야 합니다. \n 잘못된 값 : %d"
private const val ERROR_NUMBER_DUPLICATED = "로또 번호는 중복되어선 안된다. \n잘못된 값: %s"
fun create(numbers: List<Int>): Lotto = Lotto(numbers.map { LottoNumber(it) })

Choose a reason for hiding this comment

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

LottoNumber 는 숫자가 같으면 같은 클래스 일거라, 매번 생성하기보다 재사용을 해볼 수도 있을 것 같아요!

class LottoStore {

fun buyLotto(amount: Int): List<Lotto> {
require(amount in MINIMUM_AMOUNT..MAXIMUM_AMOUNT) { ERROR_CREATE_COUNT.format(amount) }

Choose a reason for hiding this comment

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

Amount 에 대한 원시값도 포장�해보고, 거기로 검증 로직을 위임해보는 것은 어떨까요?

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.

MINIMUM_AMOUNT와 MAXIMUM_AMOUNT로 1000에서 100000까지의 범위로 설정했는데 추가로 음수 예외처리가 필요한 이유에 대해 설명해주실 수 있으실까요?

Choose a reason for hiding this comment

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

앗 그러네요!
제가 다른 분 리뷰를 동시에 진행하다가 헷갈렸던 거 같습니다 😭
얘기주신 것처럼 이미 존재하는 테스트에서 커버하고 있는 영역이라 별도로 음수에 대한 예외처리는 필요없을 것 같습니다~!


return when (countOfMatch) {
6 -> FIRST
5 -> if (matchBonus) SECOND else THIRD

Choose a reason for hiding this comment

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

특정 등수에 대해 조건문을 두지 않고, 일관된 방식으로 등수를 구하도록 리펙토링 해볼 수 있을까요?
현재와 같은 구조는 보너스번호를 가지는 등수가 추가될 때 마다 if 문이 계속 추가되어야하는 구조가 될 거 같아요.

Copy link

@vagabond95 vagabond95 left a comment

Choose a reason for hiding this comment

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

로또 미션 구현하시느라 고생 많으셨습니다!

전반적으로 로직을 간결하게 잘 구현해주신 것 같아요 👍
테스트 코드도 꼼꼼하게 짜주셨습니다!

구현해주신 내용에 대해 몇가지 코멘트 남겼는데, 확인 후 리뷰요청 부탁드릴게요!

Copy link

@vagabond95 vagabond95 left a comment

Choose a reason for hiding this comment

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

코멘트 드렸던 부분들을 꼼꼼히 모두 잘 반영해주셨네요 👍
음수 관련 예외처리 로직은 제가 혼동이 있었습니다. 죄송합니다!

1단계는 크게 코멘트 드릴 부분이 보이지 않아 머지하도록 하겠습니다~!

;

companion object {
fun valueOf(countOfMatch: Int, matchBonus: Boolean): Rank {

Choose a reason for hiding this comment

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

보너스 번호 요구사항 변경이 발생해도 코드의 큰 변경없이 대응이 가능해지겠네요 👍

@vagabond95 vagabond95 merged commit e80a7c0 into woowacourse:hyemdooly Feb 19, 2023
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.

None yet

3 participants