This is an exciting release for us, led by a ton of helpful new features and patterns to make the framework easier more Swifty. Let's get right to it:
- We know it can be a huge pain to work with the
Applicative
operators. To that end, we have included an instance ofMonoidal
Functors (rather than the oldApplicative
one) forGen
that provides an overload ofzip
up to 10 parameters. This means code that previously looked like this:
public struct ArbitraryFoo {
let x : Int
let y : Int
public static func create(x : Int) -> Int -> ArbitraryFoo {
return { y in ArbitraryFoo(x: x, y: y) }
}
}
extension ArbitraryFoo : Arbitrary {
public static var arbitrary : Gen<ArbitraryFoo> {
return ArbitraryFoo.create <^> Int.arbitrary <*> Int.arbitrary
}
}
Can instead scrap the horrific initializer boilerplate and move straight to zip
then map
like so:
public struct ArbitraryFoo {
let x : Int
let y : Int
}
extension ArbitraryFoo : Arbitrary {
public static var arbitrary : Gen<ArbitraryFoo> {
return Gen<(Int, Int)>.zip(Int.arbitrary, Int.arbitrary).map(ArbitraryFoo.init)
}
}
If you ever run out of parameters, try flatMap
ing generators together.
- Enums that conform to
RawRepresentable
now have a default instance ofArbitrary
if you ask for it. To do so, simply declare your conformance to bothRawRepresentable
andArbitrary
and we'll handle the rest (thanks @bgerstle!). zip
andap
now have much, much faster implementations.- Fixed a bug (h/t @bgerstle) where replay seeds and sizes would fail to print if the test failed through
cover
age. - The framework's overall documentation and code coverage continue to improve.