github typelift/SwiftCheck v0.6.1
The Exchequer

latest releases: 0.12.0, 0.11.0, 0.10.1...
8 years ago

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 of Monoidal Functors (rather than the old Applicative one) for Gen that provides an overload of zip 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 flatMaping generators together.

  • Enums that conform to RawRepresentable now have a default instance of Arbitrary if you ask for it. To do so, simply declare your conformance to both RawRepresentable and Arbitrary and we'll handle the rest (thanks @bgerstle!).
  • zip and ap 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 coverage.
  • The framework's overall documentation and code coverage continue to improve.

Don't miss a new SwiftCheck release

NewReleases is sending notifications on new releases.