Scala Check中的forAll不运行主体

kuarbcqp  于 4个月前  发布在  Scala
关注(0)|答案(1)|浏览(51)

这是用随机整数测试矩形的表面积的代码,坐标和大小都是随机整数。只会打印“开始”,永远不会打印“内部体”。有人知道我做错了什么或忘记了什么吗?

package de.thm.move.shapes
import de.thm.move.views.shapes.ResizableRectangle
import org.scalacheck.*
import de.thm.move.MoveSpec

class ResizableRectangleTest extends MoveSpec {

  "Rectangle area procedure" should "give the correct area" in{
    val intPositiveDomain = Gen.choose[Int](1, 10000) //for the coordinates of the shape
    val intDomain = Gen.choose[Int](-10000, 10000) //for the size of the shape

    println("begin")
    //will test for random values for the coordinates and the size of the shape
    val popRectangle =  Prop.forAll(intDomain,intDomain,intPositiveDomain,intPositiveDomain) { (x: Int, y: Int, width: Int, height: Int) =>
      val rectangle: ResizableRectangle = new ResizableRectangle((x.toDouble, y.toDouble), width.toDouble, height.toDouble)
      val correctSurface: Double = width.toDouble * height.toDouble
      println("inner body")
      rectangle.getSurfaceArea() == correctSurface
    }

  }
}

字符串
我期待着许多打印的“内体”,但我得到零。
运行控制台:

vsnjm48y

vsnjm48y1#

Prop.forAll只是创建一个Prop对象,它实际上并不执行任何东西。要真正检查属性,您需要调用check方法。

相关问题