Skip to content

alexarchambault/scalacheck-shapeless

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

scalacheck-shapeless

Generation of arbitrary case classes / ADTs instances with scalacheck and shapeless

Build status Maven Central Gitter

Usage

Add to your build.sbt

libraryDependencies += "com.github.alexarchambault" %% "scalacheck-shapeless_1.16" % "1.3.1"

scalacheck-shapeless depends on shapeless 2.3 and scalacheck 1.16. It is built against scala 2.12, and 2.13.

Import the content of org.scalacheck.ScalacheckShapeless close to where you want Arbitrary type classes to be automatically available for case classes / sealed hierarchies,

import org.scalacheck.ScalacheckShapeless._

//  If you defined:

// case class Foo(i: Int, s: String, blah: Boolean)
// case class Bar(foo: Foo, other: String)

// sealed trait Base
// case class BaseIntString(i: Int, s: String) extends Base
// case class BaseDoubleBoolean(d: Double, b: Boolean) extends Base

//  then you can now do

implicitly[Arbitrary[Foo]]
implicitly[Arbitrary[Bar]]
implicitly[Arbitrary[Base]]

and in particular, while writing property-based tests,

property("some property about Foo") {
  forAll { foo: Foo =>
    // Ensure foo has the required property
  }
}

without having to define yourself an Arbitrary for Foo.

See also

License

Released under the Apache 2 license. See LICENSE file for more details.

Code of Conduct

See the Code of Conduct

About

Generation of arbitrary case classes / ADTs instances with scalacheck and shapeless

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages