In my tests I am making quite an extensive usage of Specs2 + ScalaCheck and there are some patterns to factor out. I still haven't found out if my functions should use an Arbitrary[T] or a Gen[T], since they are very similar:
sealed abstract class Arbitrary[T] {
val arbitrary: Gen[T]
}
Would a function signature looks like that:
maxSizedIntervalArbitrary[A,B](implicit ordering:Ordering[A], genStart:Arbitrary[A], genEnd:Arbitrary[B]):Arbitrary[TreeMap[A,B]]
or should I work at the Gen
abstraction level?
I'd say do both:
def maxSizedIntervalArbitrary[A,B](genStart:Gen[A], genEnd:Gen[B])(implicit ordering:Ordering[A]):Gen[TreeMap[A,B]]
implicit def maxSizedIntervalArbitrary[A,B](implicit ordering:Ordering[A], genStart:Arbitrary[A], genEnd:Arbitrary[B]):Arbitrary[TreeMap[A,B]] =
Arbitrary(maxSizedIntervalArbitrary(arbitrary[A], arbitrary[B]))
Arbitrary
is used to supply implicit Gen
s, basically, so this allows to use both forAll
variants with explicit Gen
and with implicit Arbitrary
. I don't think non-implicit
Arbitrary
is ever useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With