Difference between ScalaCheck Arbitrary [T] and Scalacheck Gen [T]

In my tests, I am making quite wide use of Specs2 + ScalaCheck, and there are some patterns to consider. I still haven't figured out if my functions should use arbitrary [T] or Gen [T], since they are very similar:

sealed abstract class Arbitrary[T] {
  val arbitrary: Gen[T]
}

Will the function signature look like this:

maxSizedIntervalArbitrary[A,B](implicit ordering:Ordering[A], genStart:Arbitrary[A], genEnd:Arbitrary[B]):Arbitrary[TreeMap[A,B]]

or should I work at the level of abstraction Gen?

+3
source share
1 answer

I would say we 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]))

ArbitraryIt is used to supply implicit Gens, mainly, so this allows you to use both options forAllwith explicit Genand implicit Arbitrary. I do not think that not always implicit Arbitrary.

+3
source

All Articles