I have generators like this:
val fooRepr = oneOf(a, b, c, d, e)
val foo = for (s <- choose(1, 5); c <- listOfN(s, fooRepr)) yield c.mkString("$")
This leads to duplication ... I can get two a, etc. I really want to create an arbitrary permutation accurate to 0 or 1, or each of a, b, c, d or e (with at least one something), in any order.
I thought there should be an easy way, but I'm struggling to find the hard way. :)
Edited: Ok, this seems to work:
val foo = for (s <- choose(1, 5);
c <- permute(s, a, b, c, d, e)) yield c.mkString("$")
def permute[T](n: Int, gs: Gen[T]*): Gen[Seq[T]] = {
val perm = Random.shuffle(gs.toList)
for {
is <- pick(n, 1 until gs.size)
xs <- sequence[List,T](is.toList.map(perm(_)))
} yield xs
}
... borrowing heavily from Gen.pick.
Thanks for your help, -Eric