Gen.choose()和.oneOf()的输出

时间:2013-11-21 02:11:38

标签: scala scalatest scalacheck

运行以下测试时,Gen()语句会打印出println

基于ScalaCheck docs,我希望输出为:

  

(数字,数字)

     

“你好”或“世界”

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)
    }
}

1 个答案:

答案 0 :(得分:5)

Gen[T]是值的生成器(类型为T),这是上面myGenc的类型。如果要打印出生成器可以生成的示例值(包装为选项),请尝试println(myGen.sample)println(c.sample)