This episode is for subscribers only. To access it, and all past and future episodes, become a subscriber today!See subscription optionsorLog in
Sign up for our weekly newsletter to be notified of new episodes, and unlock access to any subscriber-only episode of your choosing!Sign up for free episode
Gen‘s base unit of randomness,
random, which is a
Gen<UInt32> to work with Swift 4.2’s base unit of randomness, the
RandomNumberGenerator protocol. The base random type should should change to
Swift 4.2’s protocol-oriented solution allows us to define custom types that conform to
Gen to evaluate given any
RandomNumberGenerator by changing
Use a custom random number generator that can be configured with a stable seed to allow for the
Gen type to predictably generate the same random value for a given seed.
Write a helper that runs a property test for
XCTest! A property test, given a generator and a block of code, will evaluate the block of code with a configurable number of random runs. If the block returns
true, the property test passes. It it returns
false, it fails. The signature should be the following.
func forAll<A>(_ a: Gen<A>, propertyShouldHold: (A) -> Bool)
It should, internally, call an
XCTAssert function. Upon failure, print out the seed so that it can be reproduced.
forAll API to take
file: StaticString = #file, line: UInt = #line, which can be passed to XCTest in order to highlight the correct line on failure.