r - 测试显示错误结果
问题描述
我尝试通过编写测试文件“test_real_roots.R”来测试下面的示例代码。但是我得到的结果是错误的。实际上,如果您仔细观察,我的所有测试都应该通过,但我收到 1 个失败案例,不知道为什么。谁能帮我 ?
real_roots.R
real.roots <- function(a, b, c)
{
if (a == 0.)
stop("Leading term cannot be zero")
d = b*b - 4*a*c # discriminant
if (d < 0)
rr = c()
else if (d == 0)
rr = c( -b/(2*a) )
else
rr = c( (-b - sqrt(d))/(2*a),
(-b + sqrt(d))/(2*a) )
return(rr)
}
test_real_roots.R
source("real_roots.R")
library(testthat)
test_that("Distinct roots", {
roots <- real.roots(1, 80, 12)
expect_that( roots, is_a("numeric") )
expect_that( length(roots), equals(2) )
expect_that( roots[1] < roots[2], is_true() )
})
解决方案
推荐阅读
- javascript - 使用反应实现页脚不停留在底部
- python - 尝试使用条目小部件启用按钮
- angular - TypeError:无法读取未定义的属性“几何” - Angular
- javascript - 在没有/之前使用 JavaScript 提交表单的情况下验证表单元素
- python - 具有许多条件的 Pandas 列选择变得笨拙
- python - Python循环写入CSV文件
- python - 如何将浮点 argv 参数传递给另一个脚本?
- node.js - MulterError:使用 Node.js 和 Express 的文件太大
- javascript - 语音合成:如何使用 google-speech 将 en-US 口音更改为 en-IN 口音
- prestashop - 错误消息:“订单子句”中的未知列“a.id_configuration”