For more context on why this particular SCT is a good idea, you can consult the Guides. None of the examples below specify any custom messages; you can consult the function documentation to figure out how you can override the automatically generated messages.
# solution
my_fun <- function(a, b) {
abs(a) + abs(b)
}
# sct
ex() %>% check_fun_def("my_fun") %>% {
check_arguments(.)
check_call(., 1, 2) %>% check_result() %>% check_equal()
check_call(., -1, 2) %>% check_result() %>% check_equal()
check_body(.) %>% {
check_function(., "abs", index = 1)
check_function(., "abs", index = 2)
}
}
# solution
library(ggplot2)
ggplot(mtcars, aes(wt, hp)) +
geom_point()
# sct
ex() %>% {
check_function(., "ggplot") %>% check_arg("data") %>% check_equal()
check_function(., "aes") %>% {
check_arg(., "x") %>% check_equal(eval = FALSE)
check_arg(., "y") %>% check_equal(eval = FALSE)
}
check_function(., "geom_point")
}
NOTE: These exercises are pulled from a DataCamp course. You can find the source here.