From 9b43eae1c6ea595035c2d0dfa5248670ae257550 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:37:19 +0900 Subject: [PATCH 01/12] chore: update TODO --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cbae739405..ee6b811d2f 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# kotlin-lotto \ No newline at end of file +# kotlin-lotto + +## TODO +- [] 로또를 생성할 수 있다. + - [] 중복된 숫자가 포함된 로또를 생성할 수 없다. + - [] 생성된 로또 숫자들을 오름차순으로 조회할 수 있다. +- [] 로또 라운드에서 당첨번호를 통해 결과를 도출할 수 있다. + - [] 해당 라운드에서 발행된 로또중 당첨번호와 일치하는 숫자 개수별로 구분할 수 있다. + - [] 일치하는 숫자 개수별로 수익률을 알 수 있다. \ No newline at end of file From 052868f31a559b6908884f646b7b4541e137137b Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 20:18:05 +0900 Subject: [PATCH 02/12] feat: add Lotto, LottoNumber --- README.md | 6 ++-- src/main/kotlin/Lotto.kt | 31 +++++++++++++++++ src/test/kotlin/LottoNumberTest.kt | 28 ++++++++++++++++ src/test/kotlin/LottoTest.kt | 54 ++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/Lotto.kt create mode 100644 src/test/kotlin/LottoNumberTest.kt create mode 100644 src/test/kotlin/LottoTest.kt diff --git a/README.md b/README.md index ee6b811d2f..0a553be693 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # kotlin-lotto ## TODO -- [] 로또를 생성할 수 있다. - - [] 중복된 숫자가 포함된 로또를 생성할 수 없다. - - [] 생성된 로또 숫자들을 오름차순으로 조회할 수 있다. +- [x] 로또를 생성할 수 있다. + - [x] 중복된 숫자가 포함된 로또를 생성할 수 없다. + - [x] 생성된 로또 숫자들을 오름차순으로 조회할 수 있다. - [] 로또 라운드에서 당첨번호를 통해 결과를 도출할 수 있다. - [] 해당 라운드에서 발행된 로또중 당첨번호와 일치하는 숫자 개수별로 구분할 수 있다. - [] 일치하는 숫자 개수별로 수익률을 알 수 있다. \ No newline at end of file diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/Lotto.kt new file mode 100644 index 0000000000..a71a269f10 --- /dev/null +++ b/src/main/kotlin/Lotto.kt @@ -0,0 +1,31 @@ + +class Lotto(lottoNumbers: List) { + val lottoNumbers: List + + init { + require(lottoNumbers.size == LOTTO_SIZE) + hasNoDuplicatedNumbers(lottoNumbers) + + this.lottoNumbers = lottoNumbers.sortedBy { it.number } + } + + private fun hasNoDuplicatedNumbers(lottoNumbers: List) { + require(lottoNumbers.toSet().size == LOTTO_SIZE) + } + + companion object { + private const val LOTTO_SIZE = 6 + } +} + +data class LottoNumber(val number: Int) { + init { + require(MIN_LOTTO_NUMBER <= number) + require(number <= MAX_LOTTO_NUMBER) + } + + companion object { + const val MIN_LOTTO_NUMBER = 1 + const val MAX_LOTTO_NUMBER = 45 + } +} diff --git a/src/test/kotlin/LottoNumberTest.kt b/src/test/kotlin/LottoNumberTest.kt new file mode 100644 index 0000000000..b657e3992c --- /dev/null +++ b/src/test/kotlin/LottoNumberTest.kt @@ -0,0 +1,28 @@ +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import java.lang.RuntimeException + +class LottoNumberTest { + @Test + fun `로또 숫자의 범위는 1 ~ 45 까지만 허용된다`() { + // given + // when + // then + (1..45).forEach { + assertThat(LottoNumber(it).number).isEqualTo(it) + } + } + + @Test + fun `1 ~ 45 범위 이외에 로또번호는 생성될 수 없다`() { + // given + + // when + + // then + assertThrows { + LottoNumber(0).number + } + } +} diff --git a/src/test/kotlin/LottoTest.kt b/src/test/kotlin/LottoTest.kt new file mode 100644 index 0000000000..0a5ae69182 --- /dev/null +++ b/src/test/kotlin/LottoTest.kt @@ -0,0 +1,54 @@ +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import java.lang.RuntimeException + +class LottoTest { + @Test + fun `로또 숫자들로 로또를 생성할 수 있다`() { + // given + val lottoNumbers = (1..6).map { LottoNumber(it) } + + // when + // then + Lotto(lottoNumbers) + } + + @Test + fun `6개가 아닌 로또 숫자로 로또를 생성할 수 없다`() { + // given + val lottoNumbers = (1..7).map { LottoNumber(it) } + + // when + // then + assertThrows { + Lotto(lottoNumbers) + } + } + + @Test + fun `중복된 숫자들이 포함된 로또 숫자들로 로또를 생성할 수 없다`() { + // given + val lottoNumbers = (1..3).map { LottoNumber(it) } + (1..3).map { LottoNumber(it) } + + // when + // then + assertThrows { + Lotto(lottoNumbers) + } + } + + @Test + fun `로또 숫자들을 오름차순으로 조회할 수 있다`() { + // given + val reversedLottoNumbers = (1..6).reversed().map { LottoNumber(it) } + + // when + val lotto = Lotto(reversedLottoNumbers) + + // then + lotto.lottoNumbers.asSequence().windowed(2).forEach { + assertThat(it[0].number <= it[1].number).isEqualTo(true) + } + } +} From a17df7d9500c16d24778870a349cce6fc0d36b5a Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 21:44:02 +0900 Subject: [PATCH 03/12] feat: add LottoRound --- src/main/kotlin/Lotto.kt | 2 +- src/main/kotlin/LottoGenerator.kt | 15 +++++++++++++++ src/main/kotlin/LottoRound.kt | 20 ++++++++++++++++++++ src/test/kotlin/LottoRoundTest.kt | 18 ++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/LottoGenerator.kt create mode 100644 src/main/kotlin/LottoRound.kt create mode 100644 src/test/kotlin/LottoRoundTest.kt diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/Lotto.kt index a71a269f10..16afa04d35 100644 --- a/src/main/kotlin/Lotto.kt +++ b/src/main/kotlin/Lotto.kt @@ -14,7 +14,7 @@ class Lotto(lottoNumbers: List) { } companion object { - private const val LOTTO_SIZE = 6 + const val LOTTO_SIZE = 6 } } diff --git a/src/main/kotlin/LottoGenerator.kt b/src/main/kotlin/LottoGenerator.kt new file mode 100644 index 0000000000..c4fc3f8edd --- /dev/null +++ b/src/main/kotlin/LottoGenerator.kt @@ -0,0 +1,15 @@ +import Lotto.Companion.LOTTO_SIZE +import LottoNumber.Companion.MAX_LOTTO_NUMBER +import LottoNumber.Companion.MIN_LOTTO_NUMBER + +interface LottoGenerator { + fun generate(): Lotto +} + +class RandomLottoGenerator : LottoGenerator { + override fun generate(): Lotto = LOTTO_NUMBERS.shuffled().subList(0, LOTTO_SIZE).let { Lotto(it) } + + companion object { + private val LOTTO_NUMBERS = (MIN_LOTTO_NUMBER..MAX_LOTTO_NUMBER).map { LottoNumber(it) } + } +} diff --git a/src/main/kotlin/LottoRound.kt b/src/main/kotlin/LottoRound.kt new file mode 100644 index 0000000000..7f29398f57 --- /dev/null +++ b/src/main/kotlin/LottoRound.kt @@ -0,0 +1,20 @@ + +class LottoRound(private val lottoGenerator: LottoGenerator) { + constructor(lottoRoundElements: LottoRoundElements) : this(lottoRoundElements.lottoGenerator) + + private val lottos: MutableList = mutableListOf() + + fun addNewLottos(newLottoSize: Int) { + repeat(newLottoSize) { + lottos.add(newLotto()) + } + } + + fun getLottos(): List = lottos.toList() + + private fun newLotto() = lottoGenerator.generate() +} + +data class LottoRoundElements( + val lottoGenerator: LottoGenerator = RandomLottoGenerator() +) diff --git a/src/test/kotlin/LottoRoundTest.kt b/src/test/kotlin/LottoRoundTest.kt new file mode 100644 index 0000000000..19c3bb13db --- /dev/null +++ b/src/test/kotlin/LottoRoundTest.kt @@ -0,0 +1,18 @@ +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class LottoRoundTest { + + @Test + fun `새로운 로또를 개수만큼 추가할 수 있다`() { + // given + val sut = LottoRound(LottoRoundElements()) + val newLottoSize = 3 + + // when + sut.addNewLottos(newLottoSize) + + // then + assertThat(sut.getLottos().size).isEqualTo(newLottoSize) + } +} From d3e93edd183b0c356ad66d5f368798919e97c54d Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 23:21:40 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20winningLotto=20=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EB=A1=9C=EB=98=90=20=EC=B6=94=EC=B2=A8?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +-- src/main/kotlin/Lotto.kt | 17 +++++++++ src/main/kotlin/LottoResult.kt | 27 ++++++++++++++ src/main/kotlin/LottoRound.kt | 4 +++ src/main/kotlin/LottoRoundStatistics.kt | 24 +++++++++++++ src/test/kotlin/LottoRoundStatisticsTest.kt | 24 +++++++++++++ src/test/kotlin/LottoRoundTest.kt | 16 +++++++++ src/test/kotlin/LottoTest.kt | 39 +++++++++++++++++++++ 8 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/LottoResult.kt create mode 100644 src/main/kotlin/LottoRoundStatistics.kt create mode 100644 src/test/kotlin/LottoRoundStatisticsTest.kt diff --git a/README.md b/README.md index 0a553be693..9d071fffa2 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ - [x] 로또를 생성할 수 있다. - [x] 중복된 숫자가 포함된 로또를 생성할 수 없다. - [x] 생성된 로또 숫자들을 오름차순으로 조회할 수 있다. -- [] 로또 라운드에서 당첨번호를 통해 결과를 도출할 수 있다. - - [] 해당 라운드에서 발행된 로또중 당첨번호와 일치하는 숫자 개수별로 구분할 수 있다. +- [x] 로또 라운드에서 당첨번호를 통해 결과를 도출할 수 있다. + - [x] 해당 라운드에서 발행된 로또중 당첨번호와 일치하는 숫자 개수별로 구분할 수 있다. - [] 일치하는 숫자 개수별로 수익률을 알 수 있다. \ No newline at end of file diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/Lotto.kt index 16afa04d35..b233c77023 100644 --- a/src/main/kotlin/Lotto.kt +++ b/src/main/kotlin/Lotto.kt @@ -9,10 +9,27 @@ class Lotto(lottoNumbers: List) { this.lottoNumbers = lottoNumbers.sortedBy { it.number } } + fun getSameNumberCount(lotto: Lotto): Int { + return (LOTTO_SIZE * 2) - (lottoNumbers + lotto.lottoNumbers).toSet().size + } + private fun hasNoDuplicatedNumbers(lottoNumbers: List) { require(lottoNumbers.toSet().size == LOTTO_SIZE) } + 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() + } + companion object { const val LOTTO_SIZE = 6 } diff --git a/src/main/kotlin/LottoResult.kt b/src/main/kotlin/LottoResult.kt new file mode 100644 index 0000000000..0aa6c8b4c6 --- /dev/null +++ b/src/main/kotlin/LottoResult.kt @@ -0,0 +1,27 @@ +import Money.Companion.toMoney + +data class LottoResult( + val lotto: Lotto, + val winningLotto: Lotto +) { + val sameNumberCount: Int = winningLotto.getSameNumberCount(lotto) + + val reward: LottoReward? = LottoReward.getReward(sameNumberCount) +} + +enum class LottoReward(val prize: Long, val sameNumberCount: Int) { + WINNER_1ST(2000L.millionWon(), 6), + WINNDER_2ST(1500L.thousandWon(), 5), + WINNDER_3ST(50L.thousandWon(), 4), + WINNDER_4ST(5L.thousandWon(), 3); + + fun toMoney(): Money = prize.toMoney() + + companion object { + fun getReward(sameNumberCount: Int): LottoReward? = values().firstOrNull { sameNumberCount == it.sameNumberCount } + } +} + +private fun Long.thousandWon(): Long = this * 1000L + +private fun Long.millionWon(): Long = this.thousandWon().thousandWon() diff --git a/src/main/kotlin/LottoRound.kt b/src/main/kotlin/LottoRound.kt index 7f29398f57..25d2b5ed9d 100644 --- a/src/main/kotlin/LottoRound.kt +++ b/src/main/kotlin/LottoRound.kt @@ -12,6 +12,10 @@ class LottoRound(private val lottoGenerator: LottoGenerator) { fun getLottos(): List = lottos.toList() + fun lotteryDraw(winningLotto: Lotto): LottoRoundStatistics { + return LottoRoundStatistics(lottos, winningLotto) + } + private fun newLotto() = lottoGenerator.generate() } diff --git a/src/main/kotlin/LottoRoundStatistics.kt b/src/main/kotlin/LottoRoundStatistics.kt new file mode 100644 index 0000000000..7a5633741f --- /dev/null +++ b/src/main/kotlin/LottoRoundStatistics.kt @@ -0,0 +1,24 @@ +import Money.Companion.NO_MONEY +import Money.Companion.plus + +class LottoRoundStatistics( + lottos: List, + private val winningLotto: Lotto +) { + val lottoResults: List = lottos.map { LottoResult(it, winningLotto) } + + val totalPrize: Money = lottoResults.mapNotNull { it.reward } + .fold(NO_MONEY) { money, lottoReward -> + money + lottoReward.toMoney() + } +} + +@JvmInline value class Money(val value: Long) { + companion object { + fun Long.toMoney(): Money = Money(this) + + operator fun Money.plus(other: Money): Money = (value + other.value).toMoney() + + val NO_MONEY: Money = 0L.toMoney() + } +} diff --git a/src/test/kotlin/LottoRoundStatisticsTest.kt b/src/test/kotlin/LottoRoundStatisticsTest.kt new file mode 100644 index 0000000000..1241e182bc --- /dev/null +++ b/src/test/kotlin/LottoRoundStatisticsTest.kt @@ -0,0 +1,24 @@ +import Money.Companion.toMoney +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class LottoRoundStatisticsTest { + + @Test + fun `당첨된 로또를 기준으로 추첨 상세결과를 확인할 수 있다`() { + // given + val lotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } + val winningLotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } + val sut = LottoRoundStatistics(listOf(lotto), winningLotto) + + // when + // then + 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()) + } + +} \ No newline at end of file diff --git a/src/test/kotlin/LottoRoundTest.kt b/src/test/kotlin/LottoRoundTest.kt index 19c3bb13db..09f59936b8 100644 --- a/src/test/kotlin/LottoRoundTest.kt +++ b/src/test/kotlin/LottoRoundTest.kt @@ -15,4 +15,20 @@ class LottoRoundTest { // then assertThat(sut.getLottos().size).isEqualTo(newLottoSize) } + + @Test + fun `로또 추첨결과를 얻을 수 있다`() { + // given + val winningLotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } + val sut = LottoRound(LottoRoundElements()) + val newLottoSize = 3 + sut.addNewLottos(3) + + // when + val result = sut.lotteryDraw(winningLotto) + + // then + assertThat(result.lottoResults.size).isEqualTo(newLottoSize) + } + } diff --git a/src/test/kotlin/LottoTest.kt b/src/test/kotlin/LottoTest.kt index 0a5ae69182..b393938d1a 100644 --- a/src/test/kotlin/LottoTest.kt +++ b/src/test/kotlin/LottoTest.kt @@ -51,4 +51,43 @@ class LottoTest { assertThat(it[0].number <= it[1].number).isEqualTo(true) } } + + @Test + fun `같은 로또를 비교할 수 있다`() { + // given + val sameLotto1 = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val sameLotto2 = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + + // when + val isSame = sameLotto1 == sameLotto2 + + // then + assertThat(isSame).isEqualTo(true) + } + + @Test + fun `서로 같지 않은 로또를 비교할 수 있다`() { + // given + val oneToSixLotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val twoToSevenLotto = (2..7).map { LottoNumber(it) }.toList().let { Lotto(it) } + + // when + val isSame = oneToSixLotto == twoToSevenLotto + + // then + assertThat(isSame).isEqualTo(false) + } + + @Test + fun `다른 로또와 겹치는 숫자 개수를 알 수 있다`() { + // given + val oneToSixLotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val twoToSevenLotto = (2..7).map { LottoNumber(it) }.toList().let { Lotto(it) } + + // when + val shouldBeFive = oneToSixLotto.getSameNumberCount(twoToSevenLotto) + + // then + assertThat(shouldBeFive).isEqualTo(5) + } } From 2e9965aceb3882d165519f29a25abfef38e5f7b5 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 23:25:32 +0900 Subject: [PATCH 05/12] feat: add Lotto second constructor --- src/main/kotlin/Lotto.kt | 2 ++ src/test/kotlin/LottoTest.kt | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/Lotto.kt index b233c77023..0fe6e7dfa5 100644 --- a/src/main/kotlin/Lotto.kt +++ b/src/main/kotlin/Lotto.kt @@ -9,6 +9,8 @@ class Lotto(lottoNumbers: List) { this.lottoNumbers = lottoNumbers.sortedBy { it.number } } + constructor(lottoNumbers: List) : this(lottoNumbers.map { LottoNumber(it) }) + fun getSameNumberCount(lotto: Lotto): Int { return (LOTTO_SIZE * 2) - (lottoNumbers + lotto.lottoNumbers).toSet().size } diff --git a/src/test/kotlin/LottoTest.kt b/src/test/kotlin/LottoTest.kt index b393938d1a..1d01e79d88 100644 --- a/src/test/kotlin/LottoTest.kt +++ b/src/test/kotlin/LottoTest.kt @@ -14,6 +14,16 @@ class LottoTest { Lotto(lottoNumbers) } + @Test + fun `Integer list 를 통해 로또를 생성할 수 있다`() { + // given + val lottoNumbers = (1..6).toList() + + // when + // then + Lotto(lottoNumbers) + } + @Test fun `6개가 아닌 로또 숫자로 로또를 생성할 수 없다`() { // given From e0a0e3cc7c280dbdd605e83c10bde0f8821aa835 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Sun, 18 Jun 2023 23:43:59 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20reward=20?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EB=8B=B9=EC=B2=A8=EB=90=9C=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=AC=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/Lotto.kt | 4 ++-- src/main/kotlin/LottoResult.kt | 6 +++--- src/main/kotlin/LottoRoundStatistics.kt | 2 ++ src/test/kotlin/LottoRoundStatisticsTest.kt | 18 +++++++++++++++--- src/test/kotlin/LottoRoundTest.kt | 3 +-- src/test/kotlin/LottoTest.kt | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/Lotto.kt index 0fe6e7dfa5..b53c1a8ad6 100644 --- a/src/main/kotlin/Lotto.kt +++ b/src/main/kotlin/Lotto.kt @@ -9,8 +9,6 @@ class Lotto(lottoNumbers: List) { this.lottoNumbers = lottoNumbers.sortedBy { it.number } } - constructor(lottoNumbers: List) : this(lottoNumbers.map { LottoNumber(it) }) - fun getSameNumberCount(lotto: Lotto): Int { return (LOTTO_SIZE * 2) - (lottoNumbers + lotto.lottoNumbers).toSet().size } @@ -34,6 +32,8 @@ class Lotto(lottoNumbers: List) { companion object { const val LOTTO_SIZE = 6 + + fun of(lottoNumbers: List): Lotto = Lotto(lottoNumbers.map { LottoNumber(it) }) } } diff --git a/src/main/kotlin/LottoResult.kt b/src/main/kotlin/LottoResult.kt index 0aa6c8b4c6..f609ce236b 100644 --- a/src/main/kotlin/LottoResult.kt +++ b/src/main/kotlin/LottoResult.kt @@ -11,9 +11,9 @@ data class LottoResult( enum class LottoReward(val prize: Long, val sameNumberCount: Int) { WINNER_1ST(2000L.millionWon(), 6), - WINNDER_2ST(1500L.thousandWon(), 5), - WINNDER_3ST(50L.thousandWon(), 4), - WINNDER_4ST(5L.thousandWon(), 3); + WINNER_2ST(1500L.thousandWon(), 5), + WINNER_3ST(50L.thousandWon(), 4), + WINNER_4ST(5L.thousandWon(), 3); fun toMoney(): Money = prize.toMoney() diff --git a/src/main/kotlin/LottoRoundStatistics.kt b/src/main/kotlin/LottoRoundStatistics.kt index 7a5633741f..8144b3fae9 100644 --- a/src/main/kotlin/LottoRoundStatistics.kt +++ b/src/main/kotlin/LottoRoundStatistics.kt @@ -11,6 +11,8 @@ class LottoRoundStatistics( .fold(NO_MONEY) { money, lottoReward -> money + lottoReward.toMoney() } + + fun getLottoRewardOf(lottoReward: LottoReward): List = lottoResults.filter { it.reward == lottoReward }.toList() } @JvmInline value class Money(val value: Long) { diff --git a/src/test/kotlin/LottoRoundStatisticsTest.kt b/src/test/kotlin/LottoRoundStatisticsTest.kt index 1241e182bc..70d4c506eb 100644 --- a/src/test/kotlin/LottoRoundStatisticsTest.kt +++ b/src/test/kotlin/LottoRoundStatisticsTest.kt @@ -7,8 +7,8 @@ class LottoRoundStatisticsTest { @Test fun `당첨된 로또를 기준으로 추첨 상세결과를 확인할 수 있다`() { // given - val lotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } - val winningLotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } + val lotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val winningLotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } val sut = LottoRoundStatistics(listOf(lotto), winningLotto) // when @@ -21,4 +21,16 @@ class LottoRoundStatisticsTest { assertThat(sut.totalPrize).isEqualTo(LottoReward.WINNER_1ST.prize.toMoney()) } -} \ No newline at end of file + @Test + fun `LottoReward 에 해당하는 로또를 가져올 수 있다`() { + // given + val lotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val winningLotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } + val sut = LottoRoundStatistics(listOf(lotto), winningLotto) + + // when + // then + assertThat(sut.getLottoRewardOf(LottoReward.WINNER_1ST).size).isEqualTo(1) + assertThat(sut.getLottoRewardOf(LottoReward.WINNER_2ST).size).isEqualTo(0) + } +} diff --git a/src/test/kotlin/LottoRoundTest.kt b/src/test/kotlin/LottoRoundTest.kt index 09f59936b8..a20dbd6cfe 100644 --- a/src/test/kotlin/LottoRoundTest.kt +++ b/src/test/kotlin/LottoRoundTest.kt @@ -19,7 +19,7 @@ class LottoRoundTest { @Test fun `로또 추첨결과를 얻을 수 있다`() { // given - val winningLotto = (1..6).map { LottoNumber(it) }.toList().let{ Lotto(it) } + val winningLotto = (1..6).map { LottoNumber(it) }.toList().let { Lotto(it) } val sut = LottoRound(LottoRoundElements()) val newLottoSize = 3 sut.addNewLottos(3) @@ -30,5 +30,4 @@ class LottoRoundTest { // then assertThat(result.lottoResults.size).isEqualTo(newLottoSize) } - } diff --git a/src/test/kotlin/LottoTest.kt b/src/test/kotlin/LottoTest.kt index 1d01e79d88..0190ac7ed7 100644 --- a/src/test/kotlin/LottoTest.kt +++ b/src/test/kotlin/LottoTest.kt @@ -21,7 +21,7 @@ class LottoTest { // when // then - Lotto(lottoNumbers) + Lotto.of(lottoNumbers) } @Test From 2099d6b92d2de92b012f058be8eb13288340948c Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:09:02 +0900 Subject: [PATCH 07/12] feat: add LottoServiceRound --- src/main/kotlin/LottoServiceRound.kt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/kotlin/LottoServiceRound.kt diff --git a/src/main/kotlin/LottoServiceRound.kt b/src/main/kotlin/LottoServiceRound.kt new file mode 100644 index 0000000000..29530b84e5 --- /dev/null +++ b/src/main/kotlin/LottoServiceRound.kt @@ -0,0 +1,23 @@ +import Money.Companion.toMoney + +class LottoServiceRound { + private val lottoRound = LottoRound(LottoRoundElements()) + + fun buyLottos(payment: Money): List { + lottoRound.addNewLottos(payment.buyableCount()) + return lottoRound.getLottos() + } + + fun allPayment(): Money = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value).toMoney() + + fun lotteryDraw(numbers: List): LottoRoundStatistics { + val winningLotto = Lotto.of(numbers) + return lottoRound.lotteryDraw(winningLotto) + } + + private fun Money.buyableCount(): Int = (value / LOTTO_BUY_PRIZE.value).toInt() + + companion object { + private val LOTTO_BUY_PRIZE = 1000L.toMoney() + } +} From 4580dd60987815532e2709c47c29bebef420a9fb Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:10:41 +0900 Subject: [PATCH 08/12] chore: move to packages --- src/main/kotlin/{ => lotto/domain}/Lotto.kt | 2 +- src/main/kotlin/{ => lotto/domain}/LottoGenerator.kt | 8 +++++--- src/main/kotlin/{ => lotto/domain}/LottoResult.kt | 4 +++- src/main/kotlin/{ => lotto/domain}/LottoRound.kt | 2 +- .../kotlin/{ => lotto/domain}/LottoRoundStatistics.kt | 6 ++++-- src/main/kotlin/{ => lotto/domain}/LottoServiceRound.kt | 4 +++- src/test/kotlin/{ => lotto/domain}/LottoNumberTest.kt | 2 ++ .../kotlin/{ => lotto/domain}/LottoRoundStatisticsTest.kt | 4 +++- src/test/kotlin/{ => lotto/domain}/LottoRoundTest.kt | 2 ++ src/test/kotlin/{ => lotto/domain}/LottoTest.kt | 2 ++ 10 files changed, 26 insertions(+), 10 deletions(-) rename src/main/kotlin/{ => lotto/domain}/Lotto.kt (98%) rename src/main/kotlin/{ => lotto/domain}/LottoGenerator.kt (64%) rename src/main/kotlin/{ => lotto/domain}/LottoResult.kt (92%) rename src/main/kotlin/{ => lotto/domain}/LottoRound.kt (97%) rename src/main/kotlin/{ => lotto/domain}/LottoRoundStatistics.kt (87%) rename src/main/kotlin/{ => lotto/domain}/LottoServiceRound.kt (91%) rename src/test/kotlin/{ => lotto/domain}/LottoNumberTest.kt (96%) rename src/test/kotlin/{ => lotto/domain}/LottoRoundStatisticsTest.kt (95%) rename src/test/kotlin/{ => lotto/domain}/LottoRoundTest.kt (97%) rename src/test/kotlin/{ => lotto/domain}/LottoTest.kt (99%) diff --git a/src/main/kotlin/Lotto.kt b/src/main/kotlin/lotto/domain/Lotto.kt similarity index 98% rename from src/main/kotlin/Lotto.kt rename to src/main/kotlin/lotto/domain/Lotto.kt index b53c1a8ad6..baf30c90f9 100644 --- a/src/main/kotlin/Lotto.kt +++ b/src/main/kotlin/lotto/domain/Lotto.kt @@ -1,4 +1,4 @@ - +package lotto.domain class Lotto(lottoNumbers: List) { val lottoNumbers: List diff --git a/src/main/kotlin/LottoGenerator.kt b/src/main/kotlin/lotto/domain/LottoGenerator.kt similarity index 64% rename from src/main/kotlin/LottoGenerator.kt rename to src/main/kotlin/lotto/domain/LottoGenerator.kt index c4fc3f8edd..7fc279bd93 100644 --- a/src/main/kotlin/LottoGenerator.kt +++ b/src/main/kotlin/lotto/domain/LottoGenerator.kt @@ -1,6 +1,8 @@ -import Lotto.Companion.LOTTO_SIZE -import LottoNumber.Companion.MAX_LOTTO_NUMBER -import LottoNumber.Companion.MIN_LOTTO_NUMBER +package lotto.domain + +import lotto.domain.Lotto.Companion.LOTTO_SIZE +import lotto.domain.LottoNumber.Companion.MAX_LOTTO_NUMBER +import lotto.domain.LottoNumber.Companion.MIN_LOTTO_NUMBER interface LottoGenerator { fun generate(): Lotto diff --git a/src/main/kotlin/LottoResult.kt b/src/main/kotlin/lotto/domain/LottoResult.kt similarity index 92% rename from src/main/kotlin/LottoResult.kt rename to src/main/kotlin/lotto/domain/LottoResult.kt index f609ce236b..4b457676d3 100644 --- a/src/main/kotlin/LottoResult.kt +++ b/src/main/kotlin/lotto/domain/LottoResult.kt @@ -1,4 +1,6 @@ -import Money.Companion.toMoney +package lotto.domain + +import lotto.domain.Money.Companion.toMoney data class LottoResult( val lotto: Lotto, diff --git a/src/main/kotlin/LottoRound.kt b/src/main/kotlin/lotto/domain/LottoRound.kt similarity index 97% rename from src/main/kotlin/LottoRound.kt rename to src/main/kotlin/lotto/domain/LottoRound.kt index 25d2b5ed9d..bfa18c3f26 100644 --- a/src/main/kotlin/LottoRound.kt +++ b/src/main/kotlin/lotto/domain/LottoRound.kt @@ -1,4 +1,4 @@ - +package lotto.domain class LottoRound(private val lottoGenerator: LottoGenerator) { constructor(lottoRoundElements: LottoRoundElements) : this(lottoRoundElements.lottoGenerator) diff --git a/src/main/kotlin/LottoRoundStatistics.kt b/src/main/kotlin/lotto/domain/LottoRoundStatistics.kt similarity index 87% rename from src/main/kotlin/LottoRoundStatistics.kt rename to src/main/kotlin/lotto/domain/LottoRoundStatistics.kt index 8144b3fae9..f6c707c317 100644 --- a/src/main/kotlin/LottoRoundStatistics.kt +++ b/src/main/kotlin/lotto/domain/LottoRoundStatistics.kt @@ -1,5 +1,7 @@ -import Money.Companion.NO_MONEY -import Money.Companion.plus +package lotto.domain + +import lotto.domain.Money.Companion.NO_MONEY +import lotto.domain.Money.Companion.plus class LottoRoundStatistics( lottos: List, diff --git a/src/main/kotlin/LottoServiceRound.kt b/src/main/kotlin/lotto/domain/LottoServiceRound.kt similarity index 91% rename from src/main/kotlin/LottoServiceRound.kt rename to src/main/kotlin/lotto/domain/LottoServiceRound.kt index 29530b84e5..92a77f4295 100644 --- a/src/main/kotlin/LottoServiceRound.kt +++ b/src/main/kotlin/lotto/domain/LottoServiceRound.kt @@ -1,4 +1,6 @@ -import Money.Companion.toMoney +package lotto.domain + +import lotto.domain.Money.Companion.toMoney class LottoServiceRound { private val lottoRound = LottoRound(LottoRoundElements()) diff --git a/src/test/kotlin/LottoNumberTest.kt b/src/test/kotlin/lotto/domain/LottoNumberTest.kt similarity index 96% rename from src/test/kotlin/LottoNumberTest.kt rename to src/test/kotlin/lotto/domain/LottoNumberTest.kt index b657e3992c..ffff3c9279 100644 --- a/src/test/kotlin/LottoNumberTest.kt +++ b/src/test/kotlin/lotto/domain/LottoNumberTest.kt @@ -1,3 +1,5 @@ +package lotto.domain + import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows diff --git a/src/test/kotlin/LottoRoundStatisticsTest.kt b/src/test/kotlin/lotto/domain/LottoRoundStatisticsTest.kt similarity index 95% rename from src/test/kotlin/LottoRoundStatisticsTest.kt rename to src/test/kotlin/lotto/domain/LottoRoundStatisticsTest.kt index 70d4c506eb..17cd3359c5 100644 --- a/src/test/kotlin/LottoRoundStatisticsTest.kt +++ b/src/test/kotlin/lotto/domain/LottoRoundStatisticsTest.kt @@ -1,4 +1,6 @@ -import Money.Companion.toMoney +package lotto.domain + +import lotto.domain.Money.Companion.toMoney import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/LottoRoundTest.kt b/src/test/kotlin/lotto/domain/LottoRoundTest.kt similarity index 97% rename from src/test/kotlin/LottoRoundTest.kt rename to src/test/kotlin/lotto/domain/LottoRoundTest.kt index a20dbd6cfe..f5cc3951b0 100644 --- a/src/test/kotlin/LottoRoundTest.kt +++ b/src/test/kotlin/lotto/domain/LottoRoundTest.kt @@ -1,3 +1,5 @@ +package lotto.domain + import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/LottoTest.kt b/src/test/kotlin/lotto/domain/LottoTest.kt similarity index 99% rename from src/test/kotlin/LottoTest.kt rename to src/test/kotlin/lotto/domain/LottoTest.kt index 0190ac7ed7..84f07ef932 100644 --- a/src/test/kotlin/LottoTest.kt +++ b/src/test/kotlin/lotto/domain/LottoTest.kt @@ -1,3 +1,5 @@ +package lotto.domain + import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows From c10110f876fe61832d2386f1512bf3a494fb2a30 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:20:10 +0900 Subject: [PATCH 09/12] feat: add LottoInputView --- README.md | 2 +- src/main/kotlin/lotto/view/LottoInputView.kt | 22 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/lotto/view/LottoInputView.kt diff --git a/README.md b/README.md index 9d071fffa2..eab8dad43f 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ - [x] 생성된 로또 숫자들을 오름차순으로 조회할 수 있다. - [x] 로또 라운드에서 당첨번호를 통해 결과를 도출할 수 있다. - [x] 해당 라운드에서 발행된 로또중 당첨번호와 일치하는 숫자 개수별로 구분할 수 있다. - - [] 일치하는 숫자 개수별로 수익률을 알 수 있다. \ No newline at end of file + - [x] 일치하는 숫자 개수별로 수익률을 알 수 있다. \ No newline at end of file diff --git a/src/main/kotlin/lotto/view/LottoInputView.kt b/src/main/kotlin/lotto/view/LottoInputView.kt new file mode 100644 index 0000000000..6875c11f3c --- /dev/null +++ b/src/main/kotlin/lotto/view/LottoInputView.kt @@ -0,0 +1,22 @@ +package lotto.view + +import java.lang.IllegalArgumentException + +class LottoInputView { + fun inputLottoBuy(): Int { + println(LOTTO_BUY_COMMENT) + return readLineOrThrows().toInt() + } + + fun inputWinningLotto(): List { + println(WINNING_LOTTO_COMMENT) + return readLineOrThrows().split(",").map { it.toInt() } + } + + private fun readLineOrThrows(): String = readLine() ?: throw IllegalArgumentException() + + companion object { + private const val LOTTO_BUY_COMMENT = "구입금액을 입력해 주세요." + private const val WINNING_LOTTO_COMMENT = "지난 주 당첨 번호를 입력해 주세요." + } +} From 09a0b1253e4ba6cfef095f9c0e365e0618157f63 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:32:34 +0900 Subject: [PATCH 10/12] feat: add LottoOutputView --- src/main/kotlin/lotto/view/LottoOutputView.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/kotlin/lotto/view/LottoOutputView.kt diff --git a/src/main/kotlin/lotto/view/LottoOutputView.kt b/src/main/kotlin/lotto/view/LottoOutputView.kt new file mode 100644 index 0000000000..50d597b0af --- /dev/null +++ b/src/main/kotlin/lotto/view/LottoOutputView.kt @@ -0,0 +1,51 @@ +package lotto.view + +import lotto.domain.Lotto +import lotto.domain.LottoReward +import lotto.domain.LottoRoundStatistics + +class LottoOutputView { + fun currentLottos(lottos: List) { + val lottoSize = lottos.size + println("${lottoSize}개를 구매했습니다.") + repeat(lottoSize) { index -> + lottos[index].lottoNumbers.map { it.number }.joinToString(prefix = "[", separator = ", ", postfix = "]").also { println(it) } + } + } + + fun result(payment: Long, lottoRoundStatistics: LottoRoundStatistics) { + println(WINNING_C0MMENT) + + with(LottoReward.WINNER_4ST) { + lottoRoundStatistics.getLottoRewardOf(this).run { + println("${sameNumberCount}개 일치 (${prize}원)- $size") + } + } + + with(LottoReward.WINNER_3ST) { + lottoRoundStatistics.getLottoRewardOf(this).run { + println("${sameNumberCount}개 일치 (${prize}원)- $size") + } + } + + with(LottoReward.WINNER_2ST) { + lottoRoundStatistics.getLottoRewardOf(this).run { + println("${sameNumberCount}개 일치 (${prize}원)- $size") + } + } + + with(LottoReward.WINNER_1ST) { + lottoRoundStatistics.getLottoRewardOf(this).run { + println("${sameNumberCount}개 일치 (${prize}원)- $size") + } + } + + println("총 수익률은 ${lottoRoundStatistics.totalPrize.value / payment}입니다.") + } + + companion object { + private const val WINNING_C0MMENT = """당첨 통계 + |--------- + """ + } +} From 2dc324a64c0aaa5a88d2650498730c897a7ef0bf Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:48:47 +0900 Subject: [PATCH 11/12] feat: done on main --- src/main/kotlin/lotto/view/LottoInputView.kt | 2 +- src/main/kotlin/lotto/view/LottoOutputView.kt | 6 ++---- src/main/kotlin/main.kt | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/main.kt diff --git a/src/main/kotlin/lotto/view/LottoInputView.kt b/src/main/kotlin/lotto/view/LottoInputView.kt index 6875c11f3c..5c8ebf479c 100644 --- a/src/main/kotlin/lotto/view/LottoInputView.kt +++ b/src/main/kotlin/lotto/view/LottoInputView.kt @@ -10,7 +10,7 @@ class LottoInputView { fun inputWinningLotto(): List { println(WINNING_LOTTO_COMMENT) - return readLineOrThrows().split(",").map { it.toInt() } + return readLineOrThrows().replace(" ", "").split(",").map { it.toInt() } } private fun readLineOrThrows(): String = readLine() ?: throw IllegalArgumentException() diff --git a/src/main/kotlin/lotto/view/LottoOutputView.kt b/src/main/kotlin/lotto/view/LottoOutputView.kt index 50d597b0af..3ebc3e17b8 100644 --- a/src/main/kotlin/lotto/view/LottoOutputView.kt +++ b/src/main/kotlin/lotto/view/LottoOutputView.kt @@ -40,12 +40,10 @@ class LottoOutputView { } } - println("총 수익률은 ${lottoRoundStatistics.totalPrize.value / payment}입니다.") + println("총 수익률은 0.${(lottoRoundStatistics.totalPrize.value * 100 / payment)}입니다.") } companion object { - private const val WINNING_C0MMENT = """당첨 통계 - |--------- - """ + private const val WINNING_C0MMENT = "당첨 통계\n---------" } } diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt new file mode 100644 index 0000000000..f5036f4e4c --- /dev/null +++ b/src/main/kotlin/main.kt @@ -0,0 +1,21 @@ +import lotto.domain.LottoServiceRound +import lotto.domain.Money.Companion.toMoney +import lotto.view.LottoInputView +import lotto.view.LottoOutputView + +fun main() = lotto() + +fun lotto() { + val lottoServiceRound = LottoServiceRound() + val lottoInputView = LottoInputView() + val lottoOutputView = LottoOutputView() + + val payment = lottoInputView.inputLottoBuy() + lottoServiceRound.buyLottos(payment.toLong().toMoney()).also { + lottoOutputView.currentLottos(it) + } + + val winningLottoNumbers = lottoInputView.inputWinningLotto() + val lottoRoundStatistics = lottoServiceRound.lotteryDraw(winningLottoNumbers) + lottoOutputView.result(lottoServiceRound.allPayment().value, lottoRoundStatistics) +} From 7f1fde6c89fe1de1b13f1c80d54f82ae90655799 Mon Sep 17 00:00:00 2001 From: qktlf789456 <54522339+qktlf789456@users.noreply.github.com> Date: Mon, 19 Jun 2023 00:58:01 +0900 Subject: [PATCH 12/12] =?UTF-8?q?refactor:=20LottoServiceRound=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=8B=9C=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=A0=81=EC=9D=B8=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/lotto/domain/LottoServiceRound.kt | 6 +++--- src/main/kotlin/main.kt | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/lotto/domain/LottoServiceRound.kt b/src/main/kotlin/lotto/domain/LottoServiceRound.kt index 92a77f4295..2d79b945a9 100644 --- a/src/main/kotlin/lotto/domain/LottoServiceRound.kt +++ b/src/main/kotlin/lotto/domain/LottoServiceRound.kt @@ -5,19 +5,19 @@ import lotto.domain.Money.Companion.toMoney class LottoServiceRound { private val lottoRound = LottoRound(LottoRoundElements()) - fun buyLottos(payment: Money): List { + fun buyLottos(payment: Long): List { lottoRound.addNewLottos(payment.buyableCount()) return lottoRound.getLottos() } - fun allPayment(): Money = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value).toMoney() + fun allPayment(): Long = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value) fun lotteryDraw(numbers: List): LottoRoundStatistics { val winningLotto = Lotto.of(numbers) return lottoRound.lotteryDraw(winningLotto) } - private fun Money.buyableCount(): Int = (value / LOTTO_BUY_PRIZE.value).toInt() + private fun Long.buyableCount(): Int = (this / LOTTO_BUY_PRIZE.value).toInt() companion object { private val LOTTO_BUY_PRIZE = 1000L.toMoney() diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index f5036f4e4c..16022639cf 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -1,5 +1,4 @@ import lotto.domain.LottoServiceRound -import lotto.domain.Money.Companion.toMoney import lotto.view.LottoInputView import lotto.view.LottoOutputView @@ -11,11 +10,9 @@ fun lotto() { val lottoOutputView = LottoOutputView() val payment = lottoInputView.inputLottoBuy() - lottoServiceRound.buyLottos(payment.toLong().toMoney()).also { - lottoOutputView.currentLottos(it) - } + lottoServiceRound.buyLottos(payment.toLong()).also { lottoOutputView.currentLottos(it) } val winningLottoNumbers = lottoInputView.inputWinningLotto() val lottoRoundStatistics = lottoServiceRound.lotteryDraw(winningLottoNumbers) - lottoOutputView.result(lottoServiceRound.allPayment().value, lottoRoundStatistics) + lottoOutputView.result(lottoServiceRound.allPayment(), lottoRoundStatistics) }