Signed-off-by: Matt Bruce <matt.bruce1@toyota.com>
This commit is contained in:
parent
1daaf6ca22
commit
9cc7352c60
@ -7,11 +7,86 @@
|
||||
|
||||
import Testing
|
||||
@testable import Baccarat
|
||||
import CasinoKit
|
||||
|
||||
struct BaccaratTests {
|
||||
|
||||
@Test func example() async throws {
|
||||
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
|
||||
}
|
||||
|
||||
@Test func handValueCalculation() async throws {
|
||||
var hand = Hand()
|
||||
|
||||
// Test empty hand
|
||||
#expect(hand.value == 0)
|
||||
|
||||
// Test with a King (value 0) and an 8 (value 8)
|
||||
hand.addCard(Card(suit: .spades, rank: .king))
|
||||
hand.addCard(Card(suit: .hearts, rank: .eight))
|
||||
#expect(hand.value == 8)
|
||||
|
||||
// Test with two cards that sum to more than 10
|
||||
hand.clear()
|
||||
hand.addCard(Card(suit: .spades, rank: .seven))
|
||||
hand.addCard(Card(suit: .hearts, rank: .five))
|
||||
#expect(hand.value == 2) // 7 + 5 = 12, 12 % 10 = 2
|
||||
|
||||
// Test natural 9
|
||||
hand.clear()
|
||||
hand.addCard(Card(suit: .clubs, rank: .four))
|
||||
hand.addCard(Card(suit: .diamonds, rank: .five))
|
||||
#expect(hand.value == 9)
|
||||
#expect(hand.isNatural == true)
|
||||
|
||||
// Test with three cards
|
||||
hand.clear()
|
||||
hand.addCard(Card(suit: .spades, rank: .four))
|
||||
hand.addCard(Card(suit: .hearts, rank: .three))
|
||||
hand.addCard(Card(suit: .clubs, rank: .two))
|
||||
#expect(hand.value == 9) // 4 + 3 + 2 = 9
|
||||
#expect(hand.isNatural == false) // Not a natural (3 cards)
|
||||
}
|
||||
|
||||
@Test func engineHandValues() async throws {
|
||||
var engine = BaccaratEngine(deckCount: 1)
|
||||
|
||||
// Deal initial cards
|
||||
_ = engine.dealInitialCards()
|
||||
|
||||
// Verify both hands have cards
|
||||
#expect(engine.playerHand.cards.count == 2)
|
||||
#expect(engine.bankerHand.cards.count == 2)
|
||||
|
||||
// Verify hand values are calculated (between 0 and 9)
|
||||
#expect(engine.playerHand.value >= 0)
|
||||
#expect(engine.playerHand.value <= 9)
|
||||
#expect(engine.bankerHand.value >= 0)
|
||||
#expect(engine.bankerHand.value <= 9)
|
||||
}
|
||||
|
||||
@Test func gameStateHandValues() async throws {
|
||||
let state = GameState()
|
||||
|
||||
// Initially should be 0
|
||||
#expect(state.playerHandValue == 0)
|
||||
#expect(state.bankerHandValue == 0)
|
||||
|
||||
// Place a bet
|
||||
state.placeBet(type: .player, amount: 100)
|
||||
|
||||
// Deal cards
|
||||
await state.deal()
|
||||
|
||||
// After dealing, both hands should have values between 0-9
|
||||
#expect(state.playerHandValue >= 0)
|
||||
#expect(state.playerHandValue <= 9)
|
||||
#expect(state.bankerHandValue >= 0)
|
||||
#expect(state.bankerHandValue <= 9)
|
||||
|
||||
// Verify visible cards match engine cards
|
||||
#expect(state.visiblePlayerCards.count >= 2)
|
||||
#expect(state.visibleBankerCards.count >= 2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user