Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
R:如何在单元测试中使用expect_success函数?_R_Testthat - Fatal编程技术网

R:如何在单元测试中使用expect_success函数?

R:如何在单元测试中使用expect_success函数?,r,testthat,R,Testthat,我想使用testthat包测试一个表达式。在expect_success的文档中,它说明了要使用的函数的用法 expect_success(expr) 其中,expr是一个计算结果为单个期望值的表达式 例如,使用此代码 test_that("Expectation succeeds", { x <- 1:10 expect_success(mean(x)) }) 我哪里出错了?事实上,在我写问题的时候,我进一步试验了代码,发现我一开始并没有完全理解文档。此功能用于测试其他期望

我想使用
testthat
包测试一个表达式。在
expect_success
的文档中,它说明了要使用的函数的用法

expect_success(expr)
其中,
expr
是一个计算结果为单个期望值的表达式

例如,使用此代码

test_that("Expectation succeeds", {
  x <- 1:10
  expect_success(mean(x)) 
})

我哪里出错了?

事实上,在我写问题的时候,我进一步试验了代码,发现我一开始并没有完全理解文档。此功能用于测试其他期望值。因此,对于问题中使用的示例,这与预期一样有效

test_that("Expectation succeeds", {
  x <- 1:10
  expect_success(expect_type(mean(x), 'double')) 
})
测试(“期望成功”{
x
test_that("Expectation succeeds", {
  x <- 1:10
  expect_success(expect_type(mean(x), 'double')) 
})