testwhat (version 4.2.2)

test_output: Check whether the student printed something to the console

Description

Check the output of the submission to see if it contains certain elements.

Usage

"check_output"(state, regex, fixed = FALSE, trim = FALSE, times = 1, missing_msg = NULL, append = TRUE, ...)
test_output_contains(expr, times = 1, incorrect_msg = NULL)
check_output_expr(state, expr, times = 1, missing_msg = NULL, append = TRUE)

Arguments

state
the state to start from
regex
the regular expression or pattern to look for
fixed
if fixed is TRUE, regex will be sought for 'as is' in the output, if fixed = FALSE (the default), regex will be treated as actual regular expression.
trim
should the student output be trimmed, so that all newlines and spaces are removed, before checking?
times
how often should the pattern/expression output be found?
missing_msg
Custom message in case the pattern or output wasn't found often enough.
append
Whether or not to append the feedback to feedback built in previous states
...
S3 stuff
expr
The expression (as string) for which the output should be in the student's console output.
incorrect_msg
Custom message in case the output of the expression wasn't found often enough in the student's output.

Details

With check_output, you can simply specify a regular expression or pattern (depending on the value of fixed) that is looked for in the student's output.

With test_output_contains and check_output_expr you can pass an expression, that is executed and whose output is compared to the output the student generated. If the generated output is found in the student's output, the check passes.

Examples

Run this code
## Not run: 
# # Example 1
# mtcars
# 
# # SCT option 1
# test_output_contains("mtcars")
# 
# # SCT option 2
# ex() %>% check_output_expr("mtcars")
# 
# # Example 2
# print("hello!")
# 
# # SCT (robust)
# ex() %>% check_output("[H|h]ello\\!*")
# ## End(Not run)

Run the code above in your browser using DataLab