Skip to content

melrief/sonic

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
April 28, 2017 14:56
April 19, 2017 01:11
April 19, 2017 18:24
April 19, 2017 18:31
April 19, 2017 01:11
May 16, 2017 21:27
April 19, 2017 18:24

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

About

A Scala implementation of hedgehog using the typelevel libraries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages