A Scala implementation of hedgehog using the typelevel libraries
Scala
Switch branches/tags
Nothing to show
Clone or download
Latest commit d9f1aae May 19, 2017
Permalink
Failed to load latest commit information.
core Fix typos Apr 28, 2017
example first commit Apr 18, 2017
project move to sbt-travisci Apr 19, 2017
.travis.yml set java 8 for travis Apr 19, 2017
LICENSE first commit Apr 18, 2017
README.md fix Build Status link May 16, 2017
sonic.sbt move to sbt-travisci Apr 19, 2017

README.md

sonic

Build Status

Sonic is a Scala implementation of hedgehog using Cats and Monix. It is a direct translation of the haskell implementation. It's still in early stage and lacks many parts of the original library but the core data structures are all implemented and working.

Features

  • Integrated shrinking, shrinks obey invariants by construction.
  • Generators allow monadic effects.
  • Range combinators for full control over the scope of generated numbers and collections.

Example

You can find the following example in the subdirectory example.

Import sonic._, cats.syntax.flatMap._ and optionally sonic.syntax._.

import sonic._
import sonic.syntax._
import cats.syntax.flatMap._

Once you have your imports set up, you can write a simple property:

def propReverse =
    Property(
      forAll(Gen.list(Range.linear(0, 100))(Gen.alpha)) >>=
      (list => list.reverse.reverse === list)
    )

Then define a group containing the property that you have just defined:

def listPropertyGroups =
  PropertyGroup("example")(
    "propReverse" -> propReverse
  )

Finally, run the property group with Runner.checkGroup:

def main(args: Array[String]): Unit = {
  checkGroup(listPropertyGroups)
}

and run the Scala program:

$ sbt example/run
━━━ example ━━━
  propReverse: true

Contributing

Contributions are welcomed in the form of PRs.

People are expected to follow the Typelevel Code of Conduct when discussing sonic on the Github page, Gitter channel, or other venues.

License

MPL-2.0