Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JohnSundell/dab0930e12c93f1c54f09c59ed260d35 to your computer and use it in GitHub Desktop.
Save JohnSundell/dab0930e12c93f1c54f09c59ed260d35 to your computer and use it in GitHub Desktop.
class CardGameTests: XCTestCase {
func testDrawingRandomCard() {
var randomizationUpperBound: UInt32?
let deck = Deck(cards: [Card(value: .ace, suite: .spades)])
let game = CardGame(deck: deck, randomizer: { upperBound in
// Capture the upper bound to be able to assert it later
randomizationUpperBound = upperBound
// Return a constant value to remove randomness from
// our test, making it run consistently.
return 0
})
XCTAssertEqual(randomizationUpperBound, 1)
XCTAssertEqual(game.drawRandomCard(), Card(value: .ace, suite: .spades))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment