首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spec2单元测试没有编译

Spec2单元测试没有编译
EN

Stack Overflow用户
提问于 2012-06-21 14:07:40
回答 1查看 382关注 0票数 0

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

所以我用specs2写了这个

代码语言:javascript
复制
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...进行编译。

我不明白它为什么在这里要这个。我真的应该写一个隐含的我自己来做这个比较吗?

编辑,所以这个问题是纯粹的句法-见下面的答案。我对语法错误被报告为语义错误感到有点恼火,这就是为什么我从来没有想到我的列表文本是错误的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-21 15:01:02

显然,我最近花了很长时间做Python。更正列表文字语法解决了以下问题:

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11140001

复制
相关文章

相似问题

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