Skip to content

Instantly share code, notes, and snippets.

@creswick
Created March 7, 2017 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creswick/5c6018868033f5e6dfd289a962d111b9 to your computer and use it in GitHub Desktop.
Save creswick/5c6018868033f5e6dfd289a962d111b9 to your computer and use it in GitHub Desktop.
forAll fails to generate different values
import collection.mutable.Stack
import org.scalatest._
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalacheck.Gen
import org.scalacheck.Gen.{ listOf, Choose }
import org.scalacheck.Gen
// Built & run with:
// $ scalac -cp scalatest-app_2.11-3.0.1.jar:scalacheck_2.11-1.13.4.jar ExampleSpec.scala
// $ scala -cp scalatest-app_2.11-3.0.1.jar:scalacheck_2.11-1.13.4.jar org.scalatest.run ExampleSpec
class ExampleSpec extends FunSpec with Matchers with GeneratorDrivenPropertyChecks {
val nameGen = Gen.alphaNumStr.retryUntil(_.length > 0)
it("nameGen") {
forAll(nameGen) { str =>
str.length should be > (0)
}
}
it("nameGen: sample") {
val str = nameGen.sample
str match {
case None => ??? // just need something here.
case Some(s) => s.length should be > (0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment