gpt4 book ai didi

ScalaTest - 如何检查序列的所有项目是否与谓词匹配?

转载 作者:行者123 更新时间:2023-12-04 01:04:56 27 4
gpt4 key购买 nike

有没有办法显示更好的错误信息?例如下面的代码

it should "check that items satisfy predicate" in {
List(1,2,3,4,5,6).forall(x => x < 5) should equal (true)
}

只给我以下错误,没有任何描述:

"false did not equal true"

Predicate 不仅可以是least 表达式,还可以是任何其他函数。 至少我找到了https://www.scalatest.org/user_guide/using_matchers#inspectorShorthands .

最佳答案

can not only be least expression, but any other function

使用 inspector尝试

forAll (xs) { x => assert(pred(x)) }

where pred: T => Boolean,它输出索引和谓词失败的信息性错误消息,类似于

- should check that items satisfy predicate *** FAILED ***
forAll failed, because:
at index 4, pred(x) was false (HelloSpec.scala:41)
in List(1, 2, 3, 4, 5, 6) (HelloSpec.scala:41)

关于ScalaTest - 如何检查序列的所有项目是否与谓词匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66841032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com