首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scalacheck属性集

scalacheck属性集
EN

Stack Overflow用户
提问于 2015-05-04 17:48:10
回答 1查看 192关注 0票数 1

使用scalacheck,可以这样定义一些Properties

代码语言:javascript
复制
object MyProps extends Properties("MyProps") {
  property("myProp1") = forAll { (n:Int, m:Int) =>
    n+m == m+n
  }
  property("myProp2") = forAll { ... }
  property("myProp3") = forAll { ... }
}

我只想覆盖单个属性的默认最小成功测试数(minSuccessfulTests),例如仅针对"myProp2"

有没有办法做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2015-05-04 18:24:04

您可以尝试隐式转换为您自己的Prop实现,而不是PropFromFun

代码语言:javascript
复制
class PropWithParameters(prop: Prop, params: Test.Parameters) extends Prop {
    def apply(prms: Gen.Parameters) = prop(prms)

    def check(): Unit = {
         // Call super.check with params.
    }

    def withParams(moreParams: Test.Parameters): PropWithParameters = {
        // return a new instance with params merged with moreParams.
    }
}

object PropWithParameters {
    implicit def convert(input: Prop): PropWithParameters = {
        // Initialize with empty params here.

        // I'm not sure if implicits get aligned easily 
        // in case of a subclass.
    }
}

然后,您可以执行以下操作:

代码语言:javascript
复制
object MyProps extends Properties("MyProps") {
    property("myProp1") = forAll { (n:Int, m:Int) =>
        n+m == m+n
    }
    property("myProp2") = forAll { ... } withParams(customParams)
    property("myProp3") = forAll { ... }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30027112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档