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

[Step2] 로또(자동) #705

Open
wants to merge 12 commits into
base: qktlf789456
Choose a base branch
from
Open

Conversation

qktlf789456
Copy link

안녕하세요 ~ 로또미션 완료해서 리뷰 요청드립니다.
바쁘신데 새벽에 리뷰요청 죄송합니다 ㅠ

Copy link

@ohgillwhan ohgillwhan left a comment

Choose a reason for hiding this comment

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

코드 잘 작성해주셨네요~
step1 rebase 부탁드립니다~

Comment on lines +2 to +3
class Lotto(lottoNumbers: List<LottoNumber>) {
val lottoNumbers: List<LottoNumber>

Choose a reason for hiding this comment

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

정렬이라면 view의 로직이기에 init에서 제거하고, 생성자를 통해 lottoNumber를 상태로 정의하는건 어떨까요?


init {
require(lottoNumbers.size == LOTTO_SIZE)
hasNoDuplicatedNumbers(lottoNumbers)

Choose a reason for hiding this comment

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

자료구조를 잘 활용하면 이 부분은 제거해도 될거같아요.

require(lottoNumbers.size == LOTTO_SIZE)
hasNoDuplicatedNumbers(lottoNumbers)

this.lottoNumbers = lottoNumbers.sortedBy { it.number }

Choose a reason for hiding this comment

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

이건 화면의 중요한 로직이겠네요~

Comment on lines +20 to +31
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Lotto) return false

if (lottoNumbers != other.lottoNumbers) return false

return true
}

override fun hashCode(): Int {
return lottoNumbers.hashCode()
}

Choose a reason for hiding this comment

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

어떻게 하면 제거할 수 있을까요?

}

fun getSameNumberCount(lotto: Lotto): Int {
return (LOTTO_SIZE * 2) - (lottoNumbers + lotto.lottoNumbers).toSet().size

Choose a reason for hiding this comment

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

컴퓨팅 파워는 조금 더 들지라도, 조금 더 간단하게 작성할 수 있을까요?

import org.junit.jupiter.api.assertThrows
import java.lang.RuntimeException

class LottoTest {

Choose a reason for hiding this comment

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

테스트코드 내부에 반복은 없애볼까요? 필요하다면 @ParameterizedTest를 사용해볼까요?

Choose a reason for hiding this comment

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

Exception도 확실한 클래스로 검증해볼까요?~


// when
// then
Lotto.of(lottoNumbers)

Choose a reason for hiding this comment

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

생성을 했으니, 정말 넘겨준 파라미터로 잘 생성이 되었는지 검증도 해볼까요? 그것도 로직일거 같아요~

val isSame = sameLotto1 == sameLotto2

// then
assertThat(isSame).isEqualTo(true)

Choose a reason for hiding this comment

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

.isTrue는 어떨까요?

Comment on lines +18 to +23
assertThat(sut.lottoResults.size).isEqualTo(1)
assertThat(sut.lottoResults.first().lotto).isEqualTo(lotto)
assertThat(sut.lottoResults.first().winningLotto).isEqualTo(winningLotto)
assertThat(sut.lottoResults.first().sameNumberCount).isEqualTo(6)
assertThat(sut.lottoResults.first().reward).isEqualTo(LottoReward.WINNER_1ST)
assertThat(sut.totalPrize).isEqualTo(LottoReward.WINNER_1ST.prize.toMoney())

Choose a reason for hiding this comment

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

여기서 생성자를 테스트 하는 코드도 조금은 보이네요! 테스트를 조금 더 분리해볼까요?

return LottoRoundStatistics(lottos, winningLotto)
}

private fun newLotto() = lottoGenerator.generate()

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.

None yet

2 participants