check_correct checks whether a set of tests passes, and does additional, more precise tests if these tests fail. In addition to the state, it takes two code chunks;

  • diagnose_code: Set of tests that gets executed if the tests in check_code fail. These tests contain more detailed tests, to pinpoint the problem.

check_correct(state, ...)

check_or(state, ...)

Arguments

state

The state. Typically ex but can also be a lower-level state if you're using nested check_ors or check_corrects

...

sets of tests. In the case of check_correct, the first set is the check_code, the second set is the diagnose_code. For check_or, an unrestricted number of sets of tests: only one of these tests has to pass for the check_or to pass.

Details

check_correct increases the flexibility for the student: if the tests in check_code pass, the results of the tests in diagnose_code are not considered. If you test for the end result in check_code, and only do more rigorous testing in diagnose_code, you can allow for multiple solutions to a challenge.

Similarly, check_or checks whether one of many test sets pass. That way, you can allow for multiple solutions.

Both check_or and check_correct makes the state you feed it to its subtests available as . (the dot), similar to how magrittr does it.

Examples

if (FALSE) { # Example 1 solution code x <- mean(1:3) # Example SCT ex() %>% check_correct( check_object(., "x") %>% check_equal(), check_fun(., "mean") %>% check_arg("x") %>% check_equal() ) # Following submissions will all be accepted: x <- mean(1:3) x <- 2 x <- mean(-1:5) # Example 2 solution code # a <- 3; b <- 4 # Example SCT ex() %>% check_or( check_object(., 'a') %>% check_equal(), check_object(., 'b') %>% check-equal() ) # Following submissions will all be accepted: a <- 3; b <- 4 a <- 3 b <- 4 }