【发布时间】:2014-12-11 01:04:19
【问题描述】:
library(Rcpp)
cppFunction("
int fib(int n)
{
if (n < 2)
return(n);
return( fib(n-1) + fib(n-2) );
}
")
我的任务是编写几个测试来显示案例是否错误。
但是,错误信息如下。
Error during wrapup: Test failed: 'Test cppFunction'
* Not expected: 3 not equal to equals(2)
Modes of target, current: function, numeric
target, current do not match when deparsed.
* Not expected: 5 not equal to equals(5)
Modes of target, current: function, numeric
target, current do not match when deparsed.
* Not expected: 10 not equal to equals(55)
Modes of target, current: function, numeric
target, current do not match when deparsed.
* Not expected: 8 code did not generate an error.
* Not expected: 6 code did not generate an error.
* Not expected: 9 code did not generate an error.
###test that###
library(testthat)
context("Test cppFunction")
##do not know why??
test_that("Test cppFunction",{
expect_equal(3,equals(2))
expect_equal(5,equals(5))
expect_equal(10,equals(55))
expect_error(8,equals(20))
expect_error(6,equals(7))
expect_error(9,equals(25))
})
我无法弄清楚为什么测试不起作用。
【问题讨论】:
-
什么不起作用,你想达到什么目的?
-
检查函数及其计算结果 - 不是固定值
-
检查 fib(1) == 1 和 fib(3) == 2 等等。