The functions in testwhat related to testing functions allow you to test whether students correctly called particular functions, with the correct arguments and whether these arguments are correct.
The functions in testwhat related to testing functions allow you to test whether students correctly called particular functions, with the expected arguments and whether the values passed to these arguments are correct.
Here, check_function() looks for the call of round() in both student and solution code, and then check_result() runs both (in their respective environments).
Here, check_function() looks for the call of sum() in both student and solution code, and then check_result() runs both (in their respective environments).
Whenever there are is a multitude of ways to call a function
Whenever there is a multitude of ways to call a function
check_or and check_or allow you to add logic to your SCT. Instead of running all tests and failing as soon as one of the tests fail, you can conditionally execute tests, and interpret the results separately.
check_correct and check_or allow you to add logic to your SCT. Instead of running all tests and failing as soon as one of the tests fail, you can conditionally execute tests, and interpret the results separately.
As an example, suppose you want the student to calculate the mean of a vector vec and store it in res. A possible solution could be:
# vec is predefined for you
vec <- c(1, 2, 3, 4, 5, 6)
Calculate result
result <- mean(vec)
* As an example, suppose you want the student to calculate the mean of a vector `vec` and store it in `result`. A possible solution could be:
```r
# vec is predefined for you
vec <- c(1, 2, 3, 4, 5, 6)
# Calculate result
result <- mean(vec)
Because there is clearly something wrong - result is not correct - the ‘check’ sub-SCT, ex() %>% test_object("result") is executed again, but loudly this time.
Because there is clearly something wrong - result is not correct - the ‘check’ sub-SCT, ex() %>% check_object("result") is executed again, but loudly this time.
For testwhat and DataCamp’s R Backend it communicates with, this can cause problems: there’s a solution enviroment and a student environment (so that testwhat can easily compare objects that student created with the object that they should’ve created, for example with test_object())
For testwhat and DataCamp’s R Backend it communicates with, this can cause problems: there’s a solution environment and a student environment (so that testwhat can easily compare objects that student created with the object that they should’ve created, for example with check_object())
DataFrame or omitted double quotes?
print(mtcars)
orprint("mtcars")
check_output_expr()
Source
Vague definition
testwhat
related to testing functions allow you to test whether students correctly called particular functions, with the expected arguments and whether the values passed to these arguments are correct.Source
Typo
check_function()
looks for the call ofsum()
in both student and solution code, and thencheck_result()
runs both (in their respective environments).Source
Remind / remember
check_object()
andcheck_function()
often depend on both the student and solution environment.Source
check_or
orcheck_or
check_correct
andcheck_or
allow you to add logic to your SCT. Instead of running all tests and failing as soon as one of the tests fail, you can conditionally execute tests, and interpret the results separately.Source
res
orresult
Calculate result
result <- mean(vec)
Source
Remove “something”
result
is not correct, you want to dig a little deeper and see if the student used themean()
function correctly.Source
test_object()
orcheck_object()
ex() %>% check_object("result")
is executed again, but loudly this time.Source
test_object
orcheck_object
?testwhat
and DataCamp’s R Backend it communicates with, this can cause problems: there’s a solution environment and a student environment (so thattestwhat
can easily compare objects that student created with the object that they should’ve created, for example withcheck_object()
)Source
Cc @filipsch