-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: LottoResult -> MatchResult 로 명칭을 바꾸었다.
- Loading branch information
Showing
4 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
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,17 @@ | ||
package lotto.domain | ||
|
||
import java.util.EnumMap | ||
|
||
data class MatchResult( | ||
private val rankToCount: EnumMap<Rank, Int>, | ||
) { | ||
val totalPrize: Int = rankToCount.entries.sumOf { it.key.prize * it.value } | ||
|
||
fun get(rank: Rank): Int = rankToCount.getOrDefault(rank, 0) | ||
|
||
companion object { | ||
fun from(rankToCount: Map<Rank, Int>): MatchResult = MatchResult(EnumMap(rankToCount)) | ||
|
||
fun of(vararg counts: Pair<Rank, Int>): MatchResult = from(counts.toMap()) | ||
} | ||
} |
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,19 @@ | ||
package lotto.domain | ||
|
||
import io.kotest.matchers.shouldBe | ||
import org.junit.jupiter.api.Test | ||
|
||
@Suppress("NonAsciiCharacters") | ||
class MatchResultTest { | ||
@Test | ||
fun `총상금을 계산한다`() { | ||
val result = | ||
MatchResult.of( | ||
Rank.FOURTH to 1, | ||
Rank.FIFTH to 1, | ||
Rank.MISS to 12, | ||
) | ||
|
||
result.totalPrize shouldBe 55_000 | ||
} | ||
} |