-
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
π 3λ¨κ³ - λ‘λ(2λ±) #1141
Open
sjjeong
wants to merge
20
commits into
next-step:sjjeong
Choose a base branch
from
sjjeong:step3
base: sjjeong
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+297
β179
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
20d2f4b
refactor: LottoPreset λ§λ€κΈ°
sjjeong d7f1b78
refactor: Lottoμ lottoNumbersλ₯Ό SetμΌλ‘ λ³κ²½
sjjeong 4d39584
refactor: 45λΌλ 맀μ§λλ²λ₯Ό μμλ‘ μΆμΆ
sjjeong 1dbdff1
refactor: λλ©μΈ λ‘μ§μμ λ·° μμ‘΄μ± μ κ±°
sjjeong 17ffe03
refactor: domain μ±κ²©μ ν΄λμ€λ€ ν¨ν€μ§ μ΄λ
sjjeong cc4ec52
refactor: LottosλΌλ μΌκΈ 컬λ μ
μΆκ°
sjjeong 703f515
refactor: Inputμ μν΄ OutputμΌλ‘ μΆλ ₯νλ λ‘μ§μ μ΄λ
sjjeong 764631a
refactor: λΉμ²¨λ²νΈ μ
λ ₯μ λ°ννμ
λ³κ²½
sjjeong c6c5237
feat: 보λμ€λ³Ό 2λ± κΈ°λ₯ μΆκ°
sjjeong 7176b68
feat: μΆμνλ μμ λ³κ²½
sjjeong 414e25e
fix: LottoResult.totalPrizeMoney νμ
μ LongμΌλ‘ λ³κ²½
sjjeong aabe9dc
test: PrizeTestμ λΉμ²¨ κ°μ ν
μ€νΈ μΆκ°
sjjeong 02afe69
refactor: Companion Object Factory Functions μΌλ‘ λ³κ²½
sjjeong 63e5a3a
refactor: Companion Object Factory Functions μΌλ‘ λ³κ²½
sjjeong bca0683
refactor: Lottosλ‘ ν¨μ μ΄λ
sjjeong f6e9af8
refactor: method reference μ¬μ©
sjjeong 427d34e
refactor: ν¨μ 체μ΄λμμ κ°ν μΆκ°
sjjeong 8800291
refactor: ParameterizedTestλ‘ λ³κ²½
sjjeong 5b3d260
test: PrizeTestμ μΌμ΄μ€ μΆκ°
sjjeong c665edb
refactor: rangeλ₯Ό companion objectλ‘ μΆμΆ
sjjeong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package lotto.domain | ||
|
||
class Lotto private constructor(val lottoNumbers: Set<LottoNumber>) { | ||
|
||
init { | ||
val lottoNumbersSize = lottoNumbers.size | ||
require(lottoNumbersSize == LOTTO_SIZE) | ||
} | ||
|
||
constructor() : this( | ||
LottoPreset.shuffled() | ||
.take(6) | ||
.sortedBy { it.number } | ||
.toSet() | ||
) | ||
|
||
constructor(vararg number: Int) : this( | ||
number.map(::LottoNumber) | ||
.toSet() | ||
) | ||
|
||
fun countMatch(winningLotto: Lotto): Int { | ||
return lottoNumbers.intersect(winningLotto.lottoNumbers) | ||
.count() | ||
} | ||
|
||
operator fun contains(lottoNumber: LottoNumber): Boolean { | ||
return lottoNumber in lottoNumbers | ||
} | ||
|
||
companion object { | ||
private val LottoPreset = List(LottoNumber.END_LOTTO_NUMBER) { LottoNumber(it + 1) } | ||
private const val LOTTO_SIZE = 6 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package lotto.domain | ||
|
||
@JvmInline | ||
value class LottoNumber(val number: Int) { | ||
init { | ||
require(number in lottoNumberRange) | ||
} | ||
|
||
companion object { | ||
const val START_LOTTO_NUMBER = 1 | ||
const val END_LOTTO_NUMBER = 45 | ||
val lottoNumberRange = START_LOTTO_NUMBER..END_LOTTO_NUMBER | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package lotto.domain | ||
|
||
class LottoResult(private val result: Map<Prize, Int>) : Map<Prize, Int> by result { | ||
private val totalPrizeMoney: Long | ||
get() { | ||
return result.map { | ||
it.key.money.toLong() * it.value | ||
}.sum() | ||
} | ||
|
||
override fun get(key: Prize): Int { | ||
return result[key] ?: 0 | ||
} | ||
|
||
fun getRateOfReturn(money: Int): Float { | ||
return totalPrizeMoney.toFloat() / money | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package lotto.domain | ||
|
||
class Lottos(lottos: List<Lotto>) { | ||
val lottos: List<Lotto> = lottos.toList() | ||
|
||
fun getResult( | ||
winningLotto: Lotto, | ||
bonusLottoNumber: LottoNumber, | ||
): LottoResult { | ||
val result = lottos.groupingBy { lotto -> | ||
val matchCount = lotto.countMatch(winningLotto) | ||
Prize.of(matchCount = matchCount, bonusLottoNumber = bonusLottoNumber, lotto = lotto) | ||
}.eachCount() | ||
return LottoResult(result) | ||
} | ||
|
||
companion object { | ||
private const val LOTTO_PRICE = 1000 | ||
|
||
fun buyLotto(money: Int?): Lottos { | ||
requireNotNull(money) { | ||
"ꡬ맀 κΈμ‘μ nullμ΄ μλμ΄μΌ ν¨" | ||
} | ||
require(money >= LOTTO_PRICE) { | ||
"ꡬ맀 κΈμ‘μ 1000 λ³΄λ€ μ»€μΌ ν¨" | ||
} | ||
|
||
return Lottos(List(money / LOTTO_PRICE) { Lotto() }) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package lotto.domain | ||
|
||
enum class Prize(val money: Int, val count: Int) { | ||
FIRST(2_000_000_000, 6), | ||
SECOND(30_000_000, 5), | ||
THIRD(1_500_000, 5), | ||
FOURTH(50_000, 4), | ||
FIFTH(5_000, 3), | ||
NONE(0, 0), | ||
; | ||
|
||
companion object { | ||
fun of(matchCount: Int, bonusLottoNumber: LottoNumber, lotto: Lotto) = when (matchCount) { | ||
6 -> FIRST | ||
5 -> if (bonusLottoNumber in lotto) SECOND else THIRD | ||
4 -> FOURTH | ||
3 -> FIFTH | ||
else -> NONE | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package lotto.view | ||
|
||
import lotto.domain.Lotto | ||
import lotto.domain.LottoNumber | ||
|
||
class InputView { | ||
fun inputMoney(): Int { | ||
println("ꡬμ κΈμ‘μ μ λ ₯ν΄ μ£ΌμΈμ.") | ||
val input = readlnOrNull()?.toIntOrNull() | ||
requireNotNull(input) | ||
return input | ||
} | ||
|
||
fun inputWinningNumbers(): List<Int> { | ||
return readlnOrNull()?.split(",")?.map { it.trim().toInt() } ?: emptyList() | ||
fun inputWinningNumbers(): Lotto { | ||
println("μ§λ μ£Ό λΉμ²¨ λ²νΈλ₯Ό μ λ ₯ν΄ μ£ΌμΈμ.") | ||
val winningNumbers: List<Int> = readlnOrNull()?.split(",") | ||
?.map { | ||
it.trim() | ||
.toInt() | ||
} ?: emptyList() | ||
return Lotto(*winningNumbers.toIntArray()) | ||
} | ||
|
||
fun inputBonusNumber(): LottoNumber { | ||
println("보λμ€ λ³Όμ μ λ ₯ν΄ μ£ΌμΈμ.") | ||
return LottoNumber(readlnOrNull()?.toIntOrNull() ?: 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
μ¬λ¬ λ² μΈμ€ν΄μ€ννμ§ μμλ λλ κ°μ²΄μ λν΄ κ³ λ €ν΄μ£Όμ ¨λ€μ π