testwhat (version 4.2.2)

test_expression_result: Check the result, output or errors thrown by an expression

Description

Run an expression in student and solution environment and compare the result, output or error that is thrown by it.

Usage

test_expression_result(expr, eq_condition = "equivalent", incorrect_msg = NULL)
test_expression_output(expr, incorrect_msg = NULL)
test_expression_error(expr, no_error_msg = NULL, incorrect_msg = NULL)
check_expr(state, expr)
"check_result"(state, error_msg = NULL, append = TRUE, ...)
"check_output"(state, error_msg = NULL, append = TRUE, ...)
"check_error"(state, no_error_msg = NULL, append = TRUE, ...)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, eq_condition = "equivalent", ...)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, ...)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, ...)

Arguments

expr
the expression to run
eq_condition
character string indicating how to compare. See is_equal.
incorrect_msg
custom message in case the result, output or error of the expression does not correspond with the solution
no_error_msg
custom message in case the expression doesn't throw an error while it should
state
state to start from (only for check_ functions)
error_msg
custom message in case the expression throws an error while it shouldn't
append
Whether or not to append the feedback to feedback built in previous states
...
S3 stuff

Examples

Run this code
## Not run: 
# # Example 1
# a <- c(1, 2, 3, 4, 5, 6) 
# 
# # SCT option 1 to test if second and fourth element is ok:
# test_expression_result("a[c(2, 4)]")
# 
# # SCT option 2
# ex() %>% check_expr("a[c(2, 4)]") %>% check_result() %>% check_equal()
# 
# # Example 2
# my_fun <- function() { print('hello') }
# 
# # SCT option 1 to test if my_fun() produces correct output:
# test_expression_output("my_fun()")
# 
# # SCT option 2
# ex() %>% check_expr("my_fun()") %>% check_output() %>% check_equal()
# ## End(Not run)

Run the code above in your browser using DataLab