-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
111 additions
and
1 deletion.
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,9 @@ | ||
package lotto | ||
|
||
class Lotto { | ||
|
||
val numbers: List<Int> = generateLottoNumbers() | ||
companion object { | ||
const val PRICE: Int = 1000 | ||
} | ||
} |
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,10 @@ | ||
package lotto | ||
|
||
class LottoBuyer( | ||
private val money: Int | ||
) { | ||
|
||
fun buyLottoFrom(lottoStore: LottoStore): List<Lotto> { | ||
return lottoStore.sell(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,5 @@ | ||
package lotto | ||
|
||
fun generateLottoNumbers(): List<Int> { | ||
return (1..45).shuffled().take(6).sorted() | ||
} |
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,13 @@ | ||
package lotto | ||
|
||
class LottoStore { | ||
|
||
fun sell(money: Int): List<Lotto> { | ||
val count = money / Lotto.PRICE | ||
val lottos = mutableListOf<Lotto>() | ||
for (i in 1..count) { | ||
lottos.add(Lotto()) | ||
} | ||
return lottos | ||
} | ||
} |
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,20 @@ | ||
package lotto | ||
|
||
import io.kotest.matchers.collections.haveSize | ||
import io.kotest.matchers.should | ||
import org.junit.jupiter.api.Test | ||
|
||
class LottoStoreTest { | ||
|
||
@Test | ||
fun `1000원으로 로또를 구매한다`() { | ||
val lotto1 = LottoStore().sell(1000) | ||
lotto1 should haveSize(1) | ||
|
||
val lotto2 = LottoStore().sell(500) | ||
lotto2 should haveSize(0) | ||
|
||
val lotto3 = LottoStore().sell(18000) | ||
lotto3 should haveSize(18) | ||
} | ||
} |
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,43 @@ | ||
package lotto | ||
|
||
import io.kotest.matchers.collections.shouldBeOneOf | ||
import io.kotest.matchers.ints.shouldBeInRange | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.jupiter.api.Test | ||
|
||
class LottoTest { | ||
|
||
@Test | ||
fun `로또는 6자리 숫자를 가진다`() { | ||
val lotto = Lotto() | ||
lotto.numbers.size shouldBe 6 | ||
} | ||
|
||
@Test | ||
fun `로또는 1부터 45까지의 숫자를 가진다`() { | ||
val lotto = Lotto() | ||
lotto.numbers.forEach { | ||
it.shouldBeInRange(1..45) | ||
} | ||
} | ||
|
||
@Test | ||
fun `로또는 중복되지 않는 숫자를 가진다`() { | ||
val lotto = Lotto() | ||
lotto.numbers.toSet().size shouldBe 6 | ||
} | ||
|
||
@Test | ||
fun `로또는 숫자는 오름차순 정렬`() { | ||
val lotto = Lotto() | ||
lotto.numbers shouldBe lotto.numbers.sorted() | ||
} | ||
|
||
@Test | ||
fun `로또 숫자는 중복되지 않는다`() { | ||
val lotto = Lotto() | ||
lotto.numbers.forEach { | ||
it shouldBeOneOf lotto.numbers | ||
} | ||
} | ||
} |