Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.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
Unit testing Spec2单元测试未编译_Unit Testing_Scala_Specs2 - Fatal编程技术网

Unit testing Spec2单元测试未编译

Unit testing Spec2单元测试未编译,unit-testing,scala,specs2,Unit Testing,Scala,Specs2,我已经编写了一个中值函数,并想为它添加一些单元测试 所以我在specs2中写了这个 class TestStats extends Specification { "Median function " should { "be None for an empty list" in { Stats.median([]) must beNone } "be the midpoint of an odd length list" in { Stats.median([1,2,3])

我已经编写了一个中值函数,并想为它添加一些单元测试

所以我在specs2中写了这个

class TestStats extends Specification {
  "Median function " should {
    "be None for an empty list" in { Stats.median([]) must beNone }
    "be the midpoint of an odd length list" in { Stats.median([1,2,3]) must_== Some(2)}
    "be the average of the two midpoints of an even length list" in { Stats.median([1,2,3,4])     must_== Some(2.5)}
  }
}
但是,它不会编译时出现以下错误:
be None…
行上的选项[Double]=>org.specs2.execute.Result.

我不明白为什么这里会有这样的要求。我真的应该自己写一篇隐含的文章来做这个比较吗


编辑,使问题纯粹是语法性的-请参见下面我的回答。我有点恼火,语法错误被报告为语义错误,这就是为什么我从未想到我的列表文本是错误的。

显然,我最近花了太长时间在Python上。 更正列表文字语法修复了此问题:

class TestStats extends Specification {
  "Median function " should {
    "be None for an empty list" in { median(Nil) must_== None }
    "be the midpoint of an odd length list" in { median(List(1, 2, 3)) must_== Some(2) }
    "be the average of the two midpoints of an even length list" in { median(List(1, 2, 3, 4)) must_== Some(2.5) }
  }
}

你能展示更多的代码(包括导入)吗?什么是[]?乍一看,你的测试看起来是正确的。
[]
[1,2,3]
[1,2,3,4]
都是无效的Scala代码。
Stats.median
的类型签名是什么?这纯粹是一个语法问题。它甚至是用你的其他列表(python)编译的吗语法?不,我是问为什么它不会编译。我的意思是,我会预期一个不同于您的编译器错误:-)