testwhat (version 4.2.2)

test_call: Test whether a student correctly called a function/operator

Description

Test whether a student called a function correctly. Note: test_function and test_function_v2 are now identical and either can be used.

Usage

test_function(name, args = NULL, index = 1, eval = TRUE, eq_condition = "equivalent", not_called_msg = NULL, args_not_specified_msg = NULL, incorrect_msg = NULL)
test_function_v2(name, args = NULL, index = 1, eval = TRUE, eq_condition = "equivalent", not_called_msg = NULL, args_not_specified_msg = NULL, incorrect_msg = NULL)
check_function(state, name, index = 1, not_called_msg = NULL, append = TRUE)
check_operator(state, name, index = 1, append = TRUE, not_called_msg = NULL)
check_arg(state, arg, arg_not_specified_msg = NULL, append = TRUE)
"check_equal"(state, incorrect_msg = NULL, eval = TRUE, eq_condition = "equivalent", append = TRUE, ...)

Arguments

name
name of the function/operator as a string, e.g. "mean" or "+"
args
character vector of argument names that the student should have supplied in the function calls.
index
integer that specifies which call of name in the solution code will be checked.
eval
logical vector indicating whether and how to compare arguments. If eval is NA, student and solution argument are not compared. If eval is FALSE, the string versions of the arguments are compared. If eval is TRUE, the argument in the student code is evaluated in the student environment and the argument in the solution code is evaluated in the solution environment, and their results are compared. Setting this to FALSE can be useful, e.g., to test whether the student supplied a large predefined object, or when you're in a sub-SCT where the environments are not unambiguously available.
eq_condition
character vector indicating how to perform the comparison for each argument. See is_equal
not_called_msg
custom feedback message in case the student did not call the function often enough.
args_not_specified_msg
custom feedback message in case the student did call the function with the arguments listed in args
incorrect_msg
custom feedback message in case the student did not call the function with the same argument values as in the sample solution. You can specify a vector of arguments with the same length as args, to have argument-specific custom feedback.
state
state to start from (for check_ functions)
append
Whether or not to append the feedback to feedback built in previous states
arg
name of argument to specify (for check_arg)
arg_not_specified_msg
custom message in case argument was not specified (for check_arg)
...
S3 stuff

Examples

Run this code
## Not run: 
# # Example 1
# mean(1:3)
# 
# # SCT option 1
# test_function("mean", args = "x")
# 
# # SCT option 2
# ex() %>% check_function("mean") %>% check_arg("x") %>% check_equal()
# 
# 
# # Example 2
# mean(c(NA, 1, 2), na.rm = TRUE)
# 
# # SCT option 1
# test_function("mean", args = c("x", "na.rm"))
# 
# # SCT option 2
# funstate <- ex() %>% check_function("mean")
# funstate %>% check_arg("x") %>% check_equal()
# funstate %>% check_arg("na.rm") %>% check_equal()
# 
# # Example 3
# 5 + 4
# 
# # SCT
# ex() %>% check_operator("+") %>% check_result() %>% check_equal()
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace