Created
March 27, 2017 17:19
-
-
Save JohnSundell/dab0930e12c93f1c54f09c59ed260d35 to your computer and use it in GitHub Desktop.
Code sample #4 from https://medium.com/@johnsundell/simple-swift-dependency-injection-with-functions-7b0ec5b49e60
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
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