context("test-methods")
## don't need to have outputs in the test:
options("paste.output.verbose" = FALSE)
test_that("testthat valid expression", {
E <- expression(sum(seq(10)))
testthat <- testthat$new(E)
expect_equal(
testthat$expect_equal(),
"expect_equal(sum(seq(10)), 55L)"
)
expect_equal(
testthat$expect_error(),
"expect_error(sum(seq(10)))"
)
expect_warning(
testthat$expect_warning(),
"expect_warning(sum(seq(10)))"
)
expect_equal(
testthat$expect_message(),
"expect_message(sum(seq(10)))"
)
expect_equal(
testthat$expect_output(),
"expect_output(sum(seq(10)))"
)
expect_equal(
testthat$expect_s3_class(),
"expect_s3_class(sum(seq(10)), \"integer\")"
)
})
test_that("testthat error expression", {
E <- expression(2 + "a")
test <- Tests$new(E)
test$stopifnot_all.equal()
test$stopifnot_identical()
test$testthat_expect_equal()
test$testthat_expect_error()
test$testthat_expect_warning()
test$testthat_expect_message()
test$testthat_expect_output()
test$testthat_expect_s3_class()
})
test_that("testthat warning expression", {
E <- expression(any(1))
test <- testthat$new(E)
test$testthat_expect_warning()
})
test_that("time consuming expressions", {
E <- expression({Sys.sleep(5); sum(seq(10))})
test <- testthat$new(E)
test$expect_equal()
})
# -----------------------------------------------------------------------
test_that("is valid expression", {
expect_true(is_valid_expression(expression("a")))
expect_false(is_valid_expression(1))
expect_false(is_valid_expression(c(expression(1), expression(2))))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.