这是用随机整数的坐标和大小测试矩形表面积的代码。只会打印“begin”,而不会打印“inner body”。有谁知道我做错了什么或忘记了什么?
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
}
}
}
我期望有很多“内在身体”的印刷品,但我得到了零。
运行控制台:
Prop.forAll
只是创建了一个 Prop
对象,它实际上并不执行任何操作。要实际检查属性,您需要调用 check
方法。