Skip to content
/ sonic Public

A Scala implementation of hedgehog using the typelevel libraries

License

Notifications You must be signed in to change notification settings

melrief/sonic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Contributors 3

  •  
  •  
  •  

Languages