test_expr: Check the result, output or errors thrown by an expression

check_exprR Documentation

Check the result, output or errors thrown by an expression

Description

Run an expression in student and solution environment and compare the result, output or error that is thrown by it.

Usage

check_expr(state, expr)

## S3 method for class 'ExprState'
check_result(state, error_msg = NULL,
  append = TRUE, ...)

## S3 method for class 'ExprState'
check_output(state, error_msg = NULL,
  append = TRUE, ...)

## S3 method for class 'ExprState'
check_error(state, no_error_msg = NULL,
  append = TRUE, ...)

## S3 method for class 'ExprResultState'
check_equal(state, eq_condition = "equivalent",
  eq_fun = NULL, incorrect_msg = NULL, append = TRUE, ...)

## S3 method for class 'ExprOutputState'
check_equal(state, eq_fun = NULL,
  incorrect_msg = NULL, append = TRUE, ...)

## S3 method for class 'ExprErrorState'
check_equal(state, eq_fun = NULL,
  incorrect_msg = NULL, append = TRUE, ...)

Arguments

state

state to start from (only for check_ functions)

expr

the expression to run

error_msg

custom message in case the expression throws an error while it shouldn't

append

Whether or not to append the feedback to feedback built in previous states

...

S3 stuff

no_error_msg

custom message in case the expression doesn't throw an error while it should

eq_condition

character string indicating how to compare. See is_equal.

eq_fun

optional argument to specify a custom equality function. The function should take two arguments and always return a single boolean value: TRUE or FALSE.

incorrect_msg

custom message in case the result, output or error of the expression does not correspond with the solution

Examples

## Not run: 
# Example 1
a <- c(1, 2, 3, 4, 5, 6)

# SCT
ex() %>% check_expr("a[c(2, 4)]") %>% check_result() %>% check_equal()

# Example 2
my_fun <- function() { print('hello') }

# SCT
ex() %>% check_expr("my_fun()") %>% check_output() %>% check_equal()

## End(Not run)

Data-Camp/testwhat documentation built on June 24, 2022, 9:59 p.m.