testwhat (version 4.2.2)

test_code: Test the student's code as text

Description

Some rudimentary string cleaning is performed to allow for different ways of saying the same things (removing spaces, changing single quotes to double quotes, changing TRUE to T ...).

Usage

test_student_typed(strings, fixed = TRUE, times = 1, not_typed_msg = NULL)
check_code(state, regex, fixed = FALSE, times = 1, missing_msg = NULL, append = TRUE)

Arguments

strings
A set of strings/regexes that should be in the student code.
fixed
if TRUE, strings are treated literally. If FALSE, strings are treated as regex patterns.
times
how often should any of the strings be matched?
not_typed_msg
Custom feedback in case the pattern is not contained often enough in the student's submission.
state
the state to start from
regex
A set of strings/regexes that should be in the student code.
missing_msg
Custom feedback in case the pattern is not contained often enough in the student's submission.
append
Whether or not to append the feedback to feedback built in previous states

Details

Using these function should be a last resort, as there are myriad ways of solving the same problems in R!

Watch out: in test_student_typed the default is fixed = TRUE, in check_code the default is fixed = FALSE.

Examples

Run this code
## Not run: 
# # Example 1
# TRUE & FALSE
# 
# # SCT option 1
# test_student_typed(c("TRUE & FALSE", "FALSE & TRUE"))
# 
# # SCT option 2
# ex() %>% check_code(c("TRUE & FALSE", "FALSE & TRUE"), fixed = TRUE)
# 
# # Example 2:
# "Hello, world!"
# 
# # SCT option 1, robust to small typos
# test_student_typed("[H|h]ello,*\\s*[W|w]orld\\!*", fixed = FALSE)
# 
# # SCT option 2, robust to small typos
# ex() %>% check_code("[H|h]ello,*\\s*[W|w]orld\\!*")
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace