-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
62 additions
and
0 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
10 changes: 10 additions & 0 deletions
10
blackjack/src/main/java/io/github/gunkim/blackjack/domain/Dealer.java
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 io.github.gunkim.blackjack.domain; | ||
|
||
public record Dealer(CardDeck deck) { | ||
//TODO: 최초 블랙잭 시작 시 딜러는 플레이어에게 2장의 카드를 나눠줘야 함을 변수로 나타냄. 더 적절한 네이밍이 필요함. | ||
public static final int CARD_DEAL = 2; | ||
|
||
public Player deal() { | ||
return new Player(deck.draw(CARD_DEAL)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
blackjack/src/main/java/io/github/gunkim/blackjack/domain/Player.java
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 io.github.gunkim.blackjack.domain; | ||
|
||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class Player { | ||
//TODO: 일급 컬렉션 및 별도의 객체로 분리될 수 있을 것 같음. 혹은 CardDeck이 이 역할을 어느정도 할 수도 있음. | ||
private final Set<Card> cards; | ||
|
||
public Player(Collection<Card> cards) { | ||
Objects.requireNonNull(cards, "cards must not be null"); | ||
|
||
if (cards.size() != Dealer.CARD_DEAL) { | ||
throw new IllegalArgumentException("Player must have exactly %d cards".formatted(Dealer.CARD_DEAL)); | ||
} | ||
this.cards = new HashSet<>(cards); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
blackjack/src/test/java/io/github/gunkim/blackjack/domain/DealerTest.java
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,25 @@ | ||
package io.github.gunkim.blackjack.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@DisplayName("딜러는") | ||
class DealerTest { | ||
private Dealer sut; | ||
|
||
@BeforeEach | ||
void setup() { | ||
var dummyCardDeck = new CardDeck(Card.distinctCards()); | ||
this.sut = new Dealer(dummyCardDeck); | ||
} | ||
|
||
@Test | ||
@DisplayName("플레이어에게 카드를 나눠준다") | ||
void shouldDeal() { | ||
var player = sut.deal(); | ||
assertNotNull(player); | ||
} | ||
} |