Created
June 11, 2015 10:48
-
-
Save guillaumecherel/4f0532a61db73f768242 to your computer and use it in GitHub Desktop.
ScalaCheck generator for shuffled sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shuffle[T](s: Seq[T], prefix: Seq[T] = Vector()): Gen[Seq[T]] = | |
if (s.length == 0) Gen.const(prefix.toSeq) | |
else | |
Gen.choose(0, s.length - 1) | |
.flatMap { i => shuffle(s.take(i) ++ s.takeRight(s.length - i - 1), prefix :+ s(i)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment