我已经编写了一个中值函数,并希望为它添加一些单元测试。
所以我用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)}
}
}但是,它不会在No implicit view available from Option[Double] => org.specs2.execute.Result.行上使用错误"be None...进行编译。
我不明白它为什么在这里要这个。我真的应该写一个隐含的我自己来做这个比较吗?
编辑,所以这个问题是纯粹的句法-见下面的答案。我对语法错误被报告为语义错误感到有点恼火,这就是为什么我从来没有想到我的列表文本是错误的。
发布于 2012-06-21 15:01:02
显然,我最近花了很长时间做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) }
}
}https://stackoverflow.com/questions/11140001
复制相似问题