Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scalatest Matcher-检查一组值中是否存在单个值_Scala_Scalatest - Fatal编程技术网

Scalatest Matcher-检查一组值中是否存在单个值

Scalatest Matcher-检查一组值中是否存在单个值,scala,scalatest,Scala,Scalatest,我正在生成一个值,我知道它可能是什么值。我想写这个 val myInt = someFunction() myInt shouldBe oneOf (1, 2, 3) 然而,这似乎不适用于我的Scalatest 3 M15。我的解决办法是 List(myValue) should contain atMostOneOf (1, 2, 3) 读起来和理解起来要混乱得多 有什么办法可以满足我的要求吗?这似乎是一个常见的场景。其中一个只能用于比较集合的内容。您可以将一些用作简单的单元素集合: So

我正在生成一个值,我知道它可能是什么值。我想写这个

val myInt = someFunction()
myInt shouldBe oneOf (1, 2, 3)
然而,这似乎不适用于我的Scalatest 3 M15。我的解决办法是

List(myValue) should contain atMostOneOf (1, 2, 3)
读起来和理解起来要混乱得多

有什么办法可以满足我的要求吗?这似乎是一个常见的场景。

其中一个只能用于比较集合的内容。您可以将一些用作简单的单元素集合:

Some(myInt) should contain oneOf (1, 2, 3)
或者:

myInt should (equal(1) or equal(2) or equal(3))

你会得到什么错误?它会编译,但我得到测试失败1不等于1、2、3中的一个。你确定myInt的正确类型吗?我想后一个选项至少不会让人混淆。谢谢