diff --git a/src/main/kotlin/blackjack/Client.kt b/src/main/kotlin/blackjack/Client.kt new file mode 100644 index 0000000000..376a4dd880 --- /dev/null +++ b/src/main/kotlin/blackjack/Client.kt @@ -0,0 +1,16 @@ +package blackjack + +import blackjack.domain.BlackjackGame +import blackjack.domain.player.Dealer +import blackjack.view.InputView +import blackjack.view.OutputView + +fun main() { + val dealer = Dealer() + val players = InputView.inputPlayers() + val blackJackGame = BlackjackGame(dealer, players) + + OutputView.printInitGame(blackJackGame) + blackJackGame.start() + OutputView.printResult(blackJackGame.players) +} diff --git a/src/main/kotlin/blackjack/README.md b/src/main/kotlin/blackjack/README.md new file mode 100644 index 0000000000..8c0c19b629 --- /dev/null +++ b/src/main/kotlin/blackjack/README.md @@ -0,0 +1,30 @@ +## Step2 + +### 기능 목록 +- [x] 카드는 숫자와 문양을 가진다. +- [x] 카드의 숫자는 1(Ace)부터 King까지 있다. +- [x] King, Queen, Jack은 각 10으로 계산된다. +- [x] 문양은 하트, 다이아몬드, 클로버, 스페이드 4가지이다. +- [x] 카드의 총 개수는 13 * 4인 52장이다. +- [x] 카드는 문양, 숫자가 동일하다면 모두 같은 인스턴스를 반환한다. +- [x] 딜러는 카드 뭉치를 가지고 있다. +- [x] 딜러는 랜덤한 카드를 뽑을 수 있고, 뽑은 카드는 덱에서 사라진다. +- [x] 플레이어는 여러 장의 카드를 가지고 있다. +- [x] 딜러는 플레이어에게 카드를 줄 수 있다. +- [x] 플레이어는 게임 시작 시 카드 두 장을 지급받는다. +- [x] 플레이어는 카드를 뽑을 수 있다. +- [x] 게임 시작 시 플레이어의 이름을 입력할 수 있다. +- [x] 게임 시작 시 플레이어의 카드를 출력한다. +- [x] 게임 시작 후, 각 플레이어는 카드를 뽑을 지 선택할 수 있다. +- [x] 플레이어는 카드를 뽑기를 멈출 수 있다. +- [x] 플레이어는 숫자 합이 21이 넘으면 카드를 뽑을 수 없다. +- [x] Ace는 숫자 합에 따라 1 또는 11로 계산할 수 있다. +- [x] 각 플레이어의 결과를 출력할 수 있다. + +### 기능 요구사항 +- 카드의 숫자 계산은 카드 숫자를 기본으로 하며, 예외로 Ace는 1 또는 11로 계산할 수 있으며 +- King, Queen, Jack은 각각 10으로 계산한다. +- 게임을 시작하면 플레이어는 두 장의 카드를 지급 받는다. +- 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이긴다. +- 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다. + diff --git a/src/main/kotlin/blackjack/domain/BlackjackGame.kt b/src/main/kotlin/blackjack/domain/BlackjackGame.kt new file mode 100644 index 0000000000..8c358d15b0 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/BlackjackGame.kt @@ -0,0 +1,44 @@ +package blackjack.domain + +import blackjack.domain.player.Dealer +import blackjack.domain.player.Player +import blackjack.domain.state.PlayerState +import blackjack.view.InputView +import blackjack.view.OutputView + +class BlackjackGame( + private val dealer: Dealer, + val players: List +) { + init { + initGame() + } + + private fun initGame() { + repeat(INIT_DEAL_COUNT) { initDeal() } + } + + private fun initDeal() { + players.forEach { player -> dealer.deal(player) } + } + + fun isNotFinished(): Boolean = players.any { it.state == PlayerState.PLAYING } + + fun start() { + while (isNotFinished()) { + players.forEach { player -> + if (player.state == PlayerState.PLAYING) { + val inputDrawResponse = InputView.inputDrawResponse(player) + if (inputDrawResponse) { + dealer.deal(player) + OutputView.printCardsInHandWithEmptyLine(player) + } else player.stopDraw() + } + } + } + } + + companion object { + private const val INIT_DEAL_COUNT = 2 + } +} diff --git a/src/main/kotlin/blackjack/domain/card/Card.kt b/src/main/kotlin/blackjack/domain/card/Card.kt new file mode 100644 index 0000000000..bef6c34451 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/card/Card.kt @@ -0,0 +1,27 @@ +package blackjack.domain.card + +class Card private constructor ( + val suit: CardSuit, + val rank: CardRank +) { + fun print(): String = rank.forOutput + suit.forOutput + + companion object { + private const val INVALID_CARD_ERROR = "존재하지 않는 카드입니다." + val allCards = + CardSuit.values().flatMap { suit -> + CardRank.values().map { rank -> + Card(suit, rank) + } + } + + // FIXME: list O(n) 탐색 vs map 생성 +// private val map = +// allCards +// .groupBy { it.suit } +// .mapValues { it.value.associateBy { card -> card.rank } } + + fun of(suit: CardSuit, rank: CardRank): Card = + allCards.find { it.suit == suit && it.rank == rank } ?: throw IllegalArgumentException(INVALID_CARD_ERROR) + } +} diff --git a/src/main/kotlin/blackjack/domain/card/CardDeck.kt b/src/main/kotlin/blackjack/domain/card/CardDeck.kt new file mode 100644 index 0000000000..df61bbbff8 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/card/CardDeck.kt @@ -0,0 +1,11 @@ +package blackjack.domain.card + +class CardDeck { + private val cards = + Card.allCards + .shuffled() + .toMutableList() + + fun size(): Int = cards.size + fun draw(): Card = cards.removeLast() +} diff --git a/src/main/kotlin/blackjack/domain/card/CardRank.kt b/src/main/kotlin/blackjack/domain/card/CardRank.kt new file mode 100644 index 0000000000..9af689b09e --- /dev/null +++ b/src/main/kotlin/blackjack/domain/card/CardRank.kt @@ -0,0 +1,17 @@ +package blackjack.domain.card + +enum class CardRank(val value: Int, val forOutput: String) { + ACE(1, "A"), + TWO(2, "2"), + THREE(3, "3"), + FOUR(4, "4"), + FIVE(5, "5"), + SIX(6, "6"), + SEVEN(7, "7"), + EIGHT(8, "8"), + NINE(9, "9"), + TEN(10, "10"), + JACK(10, "J"), + QUEEN(10, "Q"), + KING(10, "K"); +} diff --git a/src/main/kotlin/blackjack/domain/card/CardSuit.kt b/src/main/kotlin/blackjack/domain/card/CardSuit.kt new file mode 100644 index 0000000000..c561205834 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/card/CardSuit.kt @@ -0,0 +1,8 @@ +package blackjack.domain.card + +enum class CardSuit(val forOutput: String) { + SPADE("스페이드"), + HEART("하트"), + DIAMOND("다이아몬드"), + CLUB("클로버"); +} diff --git a/src/main/kotlin/blackjack/domain/player/Dealer.kt b/src/main/kotlin/blackjack/domain/player/Dealer.kt new file mode 100644 index 0000000000..95a5da1154 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/player/Dealer.kt @@ -0,0 +1,16 @@ +package blackjack.domain.player + +import blackjack.domain.card.Card +import blackjack.domain.card.CardDeck + +class Dealer { + val cardDeck: CardDeck = CardDeck() + + fun draw(): Card { + return cardDeck.draw() + } + + fun deal(player: Player) { + player.addCard(draw()) + } +} diff --git a/src/main/kotlin/blackjack/domain/player/Player.kt b/src/main/kotlin/blackjack/domain/player/Player.kt new file mode 100644 index 0000000000..f038289ee4 --- /dev/null +++ b/src/main/kotlin/blackjack/domain/player/Player.kt @@ -0,0 +1,31 @@ +package blackjack.domain.player + +import blackjack.domain.card.Card +import blackjack.domain.card.CardRank +import blackjack.domain.state.PlayerState + +class Player( + val name: String = "player" +) { + var state: PlayerState = PlayerState.PLAYING + get() { + if (field == PlayerState.PLAYING && sum() > 21) field = PlayerState.BURST + return field + } + private set + + private val _cards = mutableListOf() + val cards: List + get() = _cards.toList() + + fun addCards(cards: List): Boolean = _cards.addAll(cards) + fun addCard(card: Card): Boolean = _cards.add(card) + fun sum(): Int { + val hasAce = cards.any { it.rank == CardRank.ACE } + val sum = cards.sumOf { it.rank.value } + + return if (hasAce && sum + 10 <= 21) sum + 10 else sum + } + + fun stopDraw() { state = PlayerState.STOP } +} diff --git a/src/main/kotlin/blackjack/domain/state/PlayerState.kt b/src/main/kotlin/blackjack/domain/state/PlayerState.kt new file mode 100644 index 0000000000..e44a0cce9c --- /dev/null +++ b/src/main/kotlin/blackjack/domain/state/PlayerState.kt @@ -0,0 +1,7 @@ +package blackjack.domain.state + +enum class PlayerState { + PLAYING, + STOP, + BURST +} diff --git a/src/main/kotlin/blackjack/view/InputNames.kt b/src/main/kotlin/blackjack/view/InputNames.kt new file mode 100644 index 0000000000..e15e6fb8df --- /dev/null +++ b/src/main/kotlin/blackjack/view/InputNames.kt @@ -0,0 +1,10 @@ +package blackjack.view + +data class InputNames( + val inputString: String +) { + + fun parseNames(): List { + return inputString.split(",") + } +} diff --git a/src/main/kotlin/blackjack/view/InputView.kt b/src/main/kotlin/blackjack/view/InputView.kt new file mode 100644 index 0000000000..07820543f4 --- /dev/null +++ b/src/main/kotlin/blackjack/view/InputView.kt @@ -0,0 +1,30 @@ +package blackjack.view + +import blackjack.domain.player.Player + +object InputView { + private const val INPUT_PLAYERS_NAME = "게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)" + private val INPUT_DRAW_RESPONSE = + { playerName: String -> "${playerName}는 한장의 카드를 더 받겠습니까? (예는 y, 아니오는 n)" } + + fun inputPlayers(): List { + val playerNames = inputPlayerNames() + + return playerNames.map { Player(it) } + } + + private fun inputPlayerNames(): List { + println(INPUT_PLAYERS_NAME) + val inputNames = InputNames(readln()) + + return inputNames.parseNames() + } + + fun inputDrawResponse(player: Player): Boolean { + println(INPUT_DRAW_RESPONSE(player.name)) + val response = readln() + require(response == "y" || response == "n") { "응답은 y, n만 가능합니다" } + + return response == "y" + } +} diff --git a/src/main/kotlin/blackjack/view/OutputView.kt b/src/main/kotlin/blackjack/view/OutputView.kt new file mode 100644 index 0000000000..987b5b6ce8 --- /dev/null +++ b/src/main/kotlin/blackjack/view/OutputView.kt @@ -0,0 +1,34 @@ +package blackjack.view + +import blackjack.domain.BlackjackGame +import blackjack.domain.player.Player +import blackjack.domain.card.Card + +object OutputView { + + fun printInitGame(blackJackGame: BlackjackGame) { + printPlayersName(blackJackGame) + blackJackGame.players.forEach { player -> printCardsInHandWithEmptyLine(player) } + } + + private fun printPlayersName(blackJackGame: BlackjackGame) { + println(blackJackGame.players.joinToString(transform = Player::name) + "에게 2장의 카드를 나누었습니다.") + } + + fun printCardsInHandWithEmptyLine(player: Player) { + printPlayerCards(player) + println() + } + + private fun printPlayerCards(player: Player) { + print("${player.name}카드: ") + print(player.cards.joinToString(transform = Card::print)) + } + + fun printResult(players: List) { + players.forEach { player -> + printPlayerCards(player) + println(" - 결과: ${player.sum()}") + } + } +} diff --git a/src/test/kotlin/blackjack/domain/BlackjackGameTest.kt b/src/test/kotlin/blackjack/domain/BlackjackGameTest.kt new file mode 100644 index 0000000000..ec9b1cedb9 --- /dev/null +++ b/src/test/kotlin/blackjack/domain/BlackjackGameTest.kt @@ -0,0 +1,64 @@ +package blackjack.domain + +import blackjack.domain.player.Dealer +import blackjack.domain.player.Player +import io.kotest.inspectors.forAll +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class BlackjackGameTest { + private lateinit var dealer: Dealer + private lateinit var players: List + private lateinit var blackjackGame: BlackjackGame + + @BeforeEach + fun beforeEach() { + dealer = Dealer() + players = listOf(Player(), Player()) + blackjackGame = BlackjackGame(dealer, players) + } + + @DisplayName("플레이어는 게임 시작 시 카드 두 장을 지급받는다.") + @Test + fun initPlayerGetCards() { + val dealer = Dealer() + val players = listOf(Player(), Player()) + players.forAll { player -> + player.cards.isEmpty() shouldBe true + } + + val blackjackGame = BlackjackGame(dealer, players) + blackjackGame.players.forAll { player -> + player.cards.size shouldBe 2 + } + } + + @DisplayName("플레이어가 한명이라도 카드를 뽑을 수 있는 상태라면 isNotFinish 메서드는 true를 반환한다.") + @Test + fun isNotFinishReturnTrue() { + val dealer = Dealer() + val players = listOf(Player(), Player()) + + val blackjackGame = BlackjackGame(dealer, players) + val actual = blackjackGame.isNotFinished() + val expect = true + + actual shouldBe expect + } + + @DisplayName("플레이어가 모두 카드를 뽑을 수 없는 상태라면 isNotFinish 메서드는 false를 반환한다.") + @Test + fun isNotFinishReturnFalse() { + val dealer = Dealer() + val players = listOf(Player(), Player()) + players.forEach(Player::stopDraw) + + val blackjackGame = BlackjackGame(dealer, players) + val actual = blackjackGame.isNotFinished() + val expect = false + + actual shouldBe expect + } +} diff --git a/src/test/kotlin/blackjack/domain/card/CardDeckTest.kt b/src/test/kotlin/blackjack/domain/card/CardDeckTest.kt new file mode 100644 index 0000000000..d27de9fadf --- /dev/null +++ b/src/test/kotlin/blackjack/domain/card/CardDeckTest.kt @@ -0,0 +1,17 @@ +package blackjack.domain.card + +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class CardDeckTest { + + @DisplayName("카드 뭉치의 카드 개수는 13 * 4인 52장이다.") + @Test + fun cardDeckSize() { + val actual = CardDeck().size() + val expect = CardSuit.values().size * CardRank.values().size + + actual shouldBe expect + } +} diff --git a/src/test/kotlin/blackjack/domain/card/CardRankTest.kt b/src/test/kotlin/blackjack/domain/card/CardRankTest.kt new file mode 100644 index 0000000000..bb428010bb --- /dev/null +++ b/src/test/kotlin/blackjack/domain/card/CardRankTest.kt @@ -0,0 +1,25 @@ +package blackjack.domain.card + +import io.kotest.matchers.collections.shouldContainAll +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class CardRankTest { + + @DisplayName("카드의 숫자는 1(Ace)부터 King까지 있다") + @Test + fun cardRank() { + val actual = CardRank.values() + + actual.size shouldBe 13 + actual.shouldContainAll( + listOf( + CardRank.ACE, CardRank.TWO, CardRank.THREE, + CardRank.FOUR, CardRank.FIVE, CardRank.SIX, + CardRank.SEVEN, CardRank.EIGHT, CardRank.NINE, CardRank.TEN, + CardRank.JACK, CardRank.QUEEN, CardRank.KING + ) + ) + } +} diff --git a/src/test/kotlin/blackjack/domain/card/CardSuitTest.kt b/src/test/kotlin/blackjack/domain/card/CardSuitTest.kt new file mode 100644 index 0000000000..ad4b54a556 --- /dev/null +++ b/src/test/kotlin/blackjack/domain/card/CardSuitTest.kt @@ -0,0 +1,17 @@ +package blackjack.domain.card + +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class CardSuitTest { + + @DisplayName("CardSuit은 SPADE, HEART, DIAMOND, CLUB 네가지이다.") + @Test + fun cardSuitType() { + val actual = CardSuit.values() + val expect = arrayOf(CardSuit.SPADE, CardSuit.HEART, CardSuit.DIAMOND, CardSuit.CLUB) + + actual shouldBe expect + } +} diff --git a/src/test/kotlin/blackjack/domain/card/CardTest.kt b/src/test/kotlin/blackjack/domain/card/CardTest.kt new file mode 100644 index 0000000000..a970fbcd4f --- /dev/null +++ b/src/test/kotlin/blackjack/domain/card/CardTest.kt @@ -0,0 +1,52 @@ +package blackjack.domain.card + +import io.kotest.inspectors.forAll +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class CardTest { + + @DisplayName("카드는 숫자와 문양을 가진다.") + @Test + fun suitAndRank() { + val rank = CardRank.ACE + val suit = CardSuit.DIAMOND + val actual = Card.of(suit, rank) + + actual.rank shouldBe rank + actual.suit shouldBe suit + } + + @DisplayName("King, Queen, Jack은 각 10으로 계산된다.") + @Test + fun jqkValueEqual10() { + val actual = listOf(CardRank.JACK, CardRank.QUEEN, CardRank.KING) + + actual.forAll { cardRank -> cardRank.value shouldBe 10 } + } + + @DisplayName("suit, rank가 같으면 동일한 Card 인스턴스가 반환된다.") + @Test + fun cardInstance() { + val suit = CardSuit.values().random() + val rank = CardRank.values().random() + + val card1 = Card.of(suit, rank) + val card2 = Card.of(suit, rank) + + val actual = card1 === card2 + actual shouldBe true + } + + @DisplayName("print메서드는 CardRank.forOutput + CardSuit.forOutput을 반환한다.") + @Test + fun print() { + val suit = CardSuit.values().random() + val rank = CardRank.values().random() + val card = Card.of(suit, rank) + + val actual = card.print() + actual shouldBe "${rank.forOutput}${suit.forOutput}" + } +} diff --git a/src/test/kotlin/blackjack/domain/player/DealerTest.kt b/src/test/kotlin/blackjack/domain/player/DealerTest.kt new file mode 100644 index 0000000000..b52d2c6860 --- /dev/null +++ b/src/test/kotlin/blackjack/domain/player/DealerTest.kt @@ -0,0 +1,55 @@ +package blackjack.domain.player + +import blackjack.domain.player.Dealer +import blackjack.domain.player.Player +import blackjack.domain.card.Card +import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeTypeOf +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class DealerTest { + private lateinit var dealer: Dealer + + @BeforeEach + fun beforeEach() { + dealer = Dealer() + } + + @DisplayName("딜러는 CardDeck을 가지고 있다.") + @Test + fun dealerHasCardDeck() { + dealer.cardDeck.shouldNotBeNull() + } + + @DisplayName("딜러는 랜덤한 카드를 뽑을 수 있다") + @Test + fun drawRandomCard() { + val actual = dealer.draw() + + actual.shouldBeTypeOf() + } + + @DisplayName("딜러가 뽑은 카드는 덱에서 사라진다.") + @Test + fun drawCardNotInDeck() { + val beforeDraw = dealer.cardDeck.size() + dealer.draw() + val afterDraw = dealer.cardDeck.size() + + afterDraw shouldBe beforeDraw - 1 + } + + @DisplayName("딜러는 플레이어에게 카드를 줄 수 있다.") + @Test + fun deal() { + val player = Player() + dealer.deal(player) + + val actual = player.cards + + actual.size shouldBe 1 + } +} diff --git a/src/test/kotlin/blackjack/domain/player/PlayerTest.kt b/src/test/kotlin/blackjack/domain/player/PlayerTest.kt new file mode 100644 index 0000000000..bf9e60cc60 --- /dev/null +++ b/src/test/kotlin/blackjack/domain/player/PlayerTest.kt @@ -0,0 +1,130 @@ +package blackjack.domain.player + +import blackjack.domain.state.PlayerState +import blackjack.domain.card.Card +import blackjack.domain.card.CardRank +import blackjack.domain.card.CardSuit +import io.kotest.inspectors.forAll +import io.kotest.matchers.collections.shouldContain +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class PlayerTest { + + @DisplayName("플레이어는 여러 장의 카드를 가지고 있다.") + @Test + fun playerHasCards() { + val cards = listOf( + Card.of(CardSuit.DIAMOND, CardRank.ACE), + Card.of(CardSuit.HEART, CardRank.ACE) + ) + val actual = Player() + actual.addCards(cards) + + actual.cards shouldBe cards + } + + @DisplayName("플레이어는 한장의 카드를 추가할 수 있다.") + @Test + fun addCard() { + val card = Card.of(CardSuit.DIAMOND, CardRank.ACE) + val actual = Player() + actual.addCard(card) + + actual.cards.size shouldBe 1 + actual.cards.shouldContain(card) + } + + @DisplayName("플레이어는 손패의 합을 알 수 있다.(Ace 제외)") + @Test + fun sum() { + val testCases = listOf( + listOf( + Card.of(CardSuit.DIAMOND, CardRank.TWO), + Card.of(CardSuit.DIAMOND, CardRank.THREE), + ) to 5, + listOf( + Card.of(CardSuit.HEART, CardRank.FOUR), + Card.of(CardSuit.HEART, CardRank.FIVE), + Card.of(CardSuit.HEART, CardRank.KING), + ) to 19 + ) + + testCases.forAll { testCase -> + val player = Player() + player.addCards(testCase.first) + val actual = player.sum() + val expect = testCase.second + + actual shouldBe expect + } + } + + @DisplayName("sum 메서드는 Ace를 1 또는 11로 계산한다.") + @Test + fun sumAce() { + val testCases = listOf( + listOf( + Card.of(CardSuit.DIAMOND, CardRank.ACE), + Card.of(CardSuit.DIAMOND, CardRank.THREE), + ) to 14, + listOf( + Card.of(CardSuit.HEART, CardRank.ACE), + Card.of(CardSuit.HEART, CardRank.KING), + ) to 21, + listOf( + Card.of(CardSuit.HEART, CardRank.ACE), + Card.of(CardSuit.HEART, CardRank.FIVE), + Card.of(CardSuit.HEART, CardRank.KING), + ) to 16, + ) + + testCases.forAll { testCase -> + val player = Player() + player.addCards(testCase.first) + val actual = player.sum() + val expect = testCase.second + + actual shouldBe expect + } + } + + @DisplayName("플레이어의 playerState 값은 카드 합이 21 이하면 Playing 초과면 Burst이다.") + @Test + fun playerState() { + val testCases = listOf( + listOf( + Card.of(CardSuit.DIAMOND, CardRank.TWO), + Card.of(CardSuit.DIAMOND, CardRank.THREE), + ) to PlayerState.PLAYING, + listOf( + Card.of(CardSuit.HEART, CardRank.JACK), + Card.of(CardSuit.HEART, CardRank.QUEEN), + Card.of(CardSuit.HEART, CardRank.KING), + ) to PlayerState.BURST + ) + + testCases.forAll { testCase -> + val player = Player() + player.addCards(testCase.first) + val actual = player.state + val expect = testCase.second + + actual shouldBe expect + } + } + + @DisplayName("플레이어는 카드 뽑기를 멈추고 상태를 변경할 수 있다.") + @Test + fun stopDraw() { + val player = Player() + player.state shouldBe PlayerState.PLAYING + + player.stopDraw() + val actual = player.state + val expect = PlayerState.STOP + + actual shouldBe expect + } +} diff --git a/src/test/kotlin/blackjack/view/InputNamesTest.kt b/src/test/kotlin/blackjack/view/InputNamesTest.kt new file mode 100644 index 0000000000..8ab93b0470 --- /dev/null +++ b/src/test/kotlin/blackjack/view/InputNamesTest.kt @@ -0,0 +1,22 @@ +package blackjack.view + +import io.kotest.inspectors.forAll +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +internal class InputNamesTest { + + @DisplayName("쉼표를 구분자로 이름이 입력되면 이름 리스트를 반환한다") + @Test + fun nameList() { + val inputs = listOf( + "name1,name2" to listOf("name1", "name2"), + "name1,name2,name3" to listOf("name1", "name2", "name3") + ) + + inputs.forAll { input -> + InputNames(input.first).parseNames() shouldBe input.second + } + } +}