Arbitrary Tuple of enums

1.3k Views Asked by At

I have an enumeration RankAndFile with 64 values representing the squares on a chessboard.

I would like a obtain a ScalaCheck Arbitrary[(RankAndFile, RankAndFile)] but I'm not sure how.

So far I have:

implicit val arbitraryRankAndFile = 
  Arbitrary(Gen.oneOf(RankAndFile.values.toSeq))

implicit val arbitraryRankAndFilePair = 
  Arbitrary.arbTuple2[RankAndFile, RankAndFile]

But the compiler complains on the second statement that it could not find implicit value for parameter a1: org.scalacheck.Arbitrary[RankAndFile.RankAndFile]. Certainly this is because the type of arbitraryRankAndFile is Arbitrary[Gen[RankAndFile]].

What should I have instead?

1

There are 1 best solutions below

0
On BEST ANSWER

The arbitrary single value was enough:

implicit def rankAndFile = Arbitrary { Gen.oneOf(RankAndFile.values.toSeq) }

The property to be checked took a tuple of RankAndFile which could be satisfied by scalacheck from this single Arbitrary value. The method Arbitrary.arbTuple2 was a red-herring.