是否可以在test_that()或Expect_XXX()调用中写入否定条件?具体来说,我想测试一个不包含子字符串的字符串,如下所示:

expect_that("Apples, Oranges, Banana", !matches('Onion'))


要么

expect_not_match("Apples, Oranges, Banana", 'Onion')


我知道我可以将Expect_true()与例如grep:

expect_true(length(grep("Onion", "Apples, Oranges, Banana")) == 0)


但这似乎不太可读。

最佳答案

testthat::not怎么样?

expect_that("Apples, Oranges, Banana", not(matches('Onion')))​​​​​​

关于r - 测试中的负面条件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30036681/

10-12 14:01