-
Notifications
You must be signed in to change notification settings - Fork 357
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
base: qktlf789456
Are you sure you want to change the base?
[Step2] 로또(자동) #705
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.
코드 잘 작성해주셨네요~
step1
rebase 부탁드립니다~
class Lotto(lottoNumbers: List<LottoNumber>) { | ||
val lottoNumbers: List<LottoNumber> |
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.
정렬이라면 view
의 로직이기에 init
에서 제거하고, 생성자를 통해 lottoNumber
를 상태로 정의하는건 어떨까요?
|
||
init { | ||
require(lottoNumbers.size == LOTTO_SIZE) | ||
hasNoDuplicatedNumbers(lottoNumbers) |
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.
자료구조를 잘 활용하면 이 부분은 제거해도 될거같아요.
require(lottoNumbers.size == LOTTO_SIZE) | ||
hasNoDuplicatedNumbers(lottoNumbers) | ||
|
||
this.lottoNumbers = lottoNumbers.sortedBy { it.number } |
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.
이건 화면의 중요한 로직이겠네요~
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() | ||
} |
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 getSameNumberCount(lotto: Lotto): Int { | ||
return (LOTTO_SIZE * 2) - (lottoNumbers + lotto.lottoNumbers).toSet().size |
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.
컴퓨팅 파워는 조금 더 들지라도, 조금 더 간단하게 작성할 수 있을까요?
import org.junit.jupiter.api.assertThrows | ||
import java.lang.RuntimeException | ||
|
||
class LottoTest { |
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.
테스트코드 내부에 반복은 없애볼까요? 필요하다면 @ParameterizedTest
를 사용해볼까요?
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.
Exception
도 확실한 클래스로 검증해볼까요?~
|
||
// when | ||
// then | ||
Lotto.of(lottoNumbers) |
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.
생성을 했으니, 정말 넘겨준 파라미터로 잘 생성이 되었는지 검증도 해볼까요? 그것도 로직일거 같아요~
val isSame = sameLotto1 == sameLotto2 | ||
|
||
// then | ||
assertThat(isSame).isEqualTo(true) |
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.
.isTrue
는 어떨까요?
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()) |
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.
여기서 생성자를 테스트 하는 코드도 조금은 보이네요! 테스트를 조금 더 분리해볼까요?
return LottoRoundStatistics(lottos, winningLotto) | ||
} | ||
|
||
private fun newLotto() = lottoGenerator.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.
좋네요~ 이런 명확한 함수는 좋습니다~
안녕하세요 ~ 로또미션 완료해서 리뷰 요청드립니다.
바쁘신데 새벽에 리뷰요청 죄송합니다 ㅠ