Gen[T]
is a generator of values (of type T
), and this is the type of both myGen
and c
above. If you want to print out example values of what the generators can produce (wrapped as an Option), try println(myGen.sample)
and println(c.sample)
.
Output of Gen.choose() and .oneOf()
-
03-08-2022 - |
Question
When running the below test, Gen()
gets printed out for both println
statements.
Based on the ScalaCheck docs, I would've expected the output to be:
(number, number)
"Hello" or "World"
class TestScalaCheck extends FlatSpec {
@author first test - https://github.com/rickynils/scalacheck/wiki/User-Guide
"a test" should "print out Gen.choose(1, 100)" in {
val myGen = for {
n <- Gen.choose(10,20)
m <- Gen.choose(2*n, 500)
} yield (n,m)
println(myGen)
val c = Gen.oneOf("Hello", "World")
println(c)
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow