scalacheck case class random data generator

前端 未结 3 1025
遇见更好的自我
遇见更好的自我 2021-01-01 19:34

I\'m trying to generate random data with Scalacheck. I have a hierarchy of case classes with many properties. The only way I\'ve found so far to populate the case classes is

相关标签:
3条回答
  • 2021-01-01 20:17

    Another approach would be DanielaSfregola/random-data-generator, A library to generate random data for test purposes, using ScalaCheck and scalacheck-shapeless.

    For Scala 2.11.8 or more, it can generate for you the initialization sequence for a case class with many field.

    0 讨论(0)
  • 2021-01-01 20:19

    There is a shapeless based Scalacheck library https://github.com/alexarchambault/scalacheck-shapeless what you might be looking for

    0 讨论(0)
  • 2021-01-01 20:25

    I am sure somebody will come up with a solution that abstracts over arity using shapeless. But there are some helper methods to generate Gen[T] instances from functions of varying arity, which can be used with the apply method of the case class companion object

    case class Data(a: String, b: String, c: String)
    
    val dataArb = Arbitrary(Gen.resultOf(Data))
    // equivalent to
    // val f: (String, String, String) => Data = Data.apply
    // val gen: Gen[Data] = Gen.resultOf(f)
    // val arb: Arbitrary[Data] = Arbitrary(gen)
    
    0 讨论(0)
提交回复
热议问题