Scalacheck Magnolia


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.github.chocpanda
ArtifactId

ArtifactId

scalacheck-magnolia_2.13
Last Version

Last Version

0.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

Scalacheck Magnolia
Scalacheck Magnolia
Project URL

Project URL

https://github.com/ChocPanda/scalacheck-magnolia
Project Organization

Project Organization

com.github.chocpanda
Source Code Management

Source Code Management

https://github.com/ChocPanda/scalacheck-magnolia

Download scalacheck-magnolia_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chocpanda/scalacheck-magnolia_2.13/ -->
<dependency>
    <groupId>com.github.chocpanda</groupId>
    <artifactId>scalacheck-magnolia_2.13</artifactId>
    <version>0.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chocpanda/scalacheck-magnolia_2.13/
implementation 'com.github.chocpanda:scalacheck-magnolia_2.13:0.6.0'
// https://jarcasting.com/artifacts/com.github.chocpanda/scalacheck-magnolia_2.13/
implementation ("com.github.chocpanda:scalacheck-magnolia_2.13:0.6.0")
'com.github.chocpanda:scalacheck-magnolia_2.13:jar:0.6.0'
<dependency org="com.github.chocpanda" name="scalacheck-magnolia_2.13" rev="0.6.0">
  <artifact name="scalacheck-magnolia_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chocpanda', module='scalacheck-magnolia_2.13', version='0.6.0')
)
libraryDependencies += "com.github.chocpanda" % "scalacheck-magnolia_2.13" % "0.6.0"
[com.github.chocpanda/scalacheck-magnolia_2.13 "0.6.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.3
com.propensive : magnolia_2.13 jar 0.17.0
org.scalacheck : scalacheck_2.13 jar 1.15.2

provided (1)

Group / Artifact Type Version
org.scala-lang : scala-reflect jar 2.12.11

test (1)

Group / Artifact Type Version
com.lihaoyi : utest_2.13 jar 0.7.5

Project Modules

There are no modules declared in this project.

Scalacheck Magnolia

Codacy Badge Build Status 2.12 - Maven Central 2.13 - Maven Central

This library will derive instances of the Arbitrary type class from scalacheck using Magnolia. The functionality would be very similar to scalacheck-shapeless but hopefully with the compile time benefits that magnolia provides over shapeless.

It's very simple to use simply add to your build.sbt:

    libraryDependencies += "com.github.chocpanda" %% "scalacheck-magnolia" % "0.5.1"

and import:

   import org.scalacheck.magnolia._

into the relevant test files for instances of Arbitrary for all your testing needs

Examples

It can derive arbitrary instances of product or sum types, and because magnolia does so recursively it can also derive instances of nested data types.

package org.scalacheck.magnolia.example

import org.scalacheck.magnolia._
import org.scalacheck.Prop._
import utest._

object ExampleTest extends TestSuite {
    
    sealed trait Entity
    
    final case class Company(name: String)                      extends Entity
    final case class Human(name: String, age: Int)              extends Entity
    final case class Address(line1: String, occupant: Human)    extends Entity

    val tests = Tests {
        "My first test description" - forAll {
            company: Company =>
            // Test for an arbitrary company...
        }.check()
        
        "My second test description" - forAll {
            entity: Entity =>
            // Test for an arbitrary Entity... Could be any Company, Human or Address
        }.check()
    }
}

It works with recursive types:

package org.scalacheck.magnolia.example

import org.scalacheck.magnolia._
import org.scalacheck.Prop._
import utest._

object ExampleTest extends TestSuite {

    sealed trait Tree
    final case class Leaf(value: String)             extends Tree
    final case class Branch(left: Tree, right: Tree) extends Tree

    val tests = Tests {
        "My test description" - forAll {
            tree: Tree =>
            // Test for an arbitrary tree...
        }.check()
    }
}

It even works with Generics:

package org.scalacheck.magnolia.example

import org.scalacheck.magnolia._
import org.scalacheck.Prop._
import utest._

object ExampleTest extends TestSuite {
    
    sealed trait GTree[+T]
    final case class GLeaf[+T](value: T)                          extends GTree[T]
    final case class GBranch[+T](left: GTree[T], right: GTree[T]) extends GTree[T]

    val tests = Tests {
        "My first test description" - forAll {
            gTree: GTree[Int] =>
            // Test for an arbitrary IntTree...
        }.check()
    }
}

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Along with any pull requests, please state that the contribution is your original work and that you license the work to the project under the project's open source license. Whether or not you state this explicitly, by submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project's open source license and warrant that you have the legal authority to do so.

License

This code is open source software licensed under the Apache-2.0 license.

Versions

Version
0.6.0
0.5.1
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0