datacamp / testwhat

Write Submission Correctness Tests for R exercises
https://datacamp.github.io/testwhat
GNU Affero General Public License v3.0
33 stars 25 forks source link

function to create SCT boilerplate from code #88

Open machow opened 7 years ago

machow commented 7 years ago

This has come up in a few discussions, so putting here to track.

What is SCT boilerplate?

Suppose a person writes a script with three variables, as below..

x <- 1
y <- 2
z <- 3

Then, it may be useful to generate this SCT boilerplate..

ex() %>% {
  check_error(.)
  check_object(., "x") %>% check_equal()
  check_object(., "y") %>% check_equal()
  check_object(., "z") %>% check_equal()
}
success_msg()

Other cases might include..

  1. Don't use check_object on iterator variables
  2. Check output whenever there is a print expression
  3. A chain of checks that focus in on blocks of code (e.g. an if statement in a for loop)
  4. Somehow knowing to include test_student_typed with the correct string

General Note: testwhat is set up to look at specific pieces of code or output, given an SCT. The issue of boilerplate is essentially inverting that: providing an SCT, given a specific piece of code or output.

Testing printed output

Could look search through expressions for print calls...

exp <- expression({x <- 1; print(x + 1)})
exp[[1]][[3]][[1]]     # print
exp[[1]][[3]][[2]]     # x + 1
machow commented 7 years ago

As an alternative, there has been a lot of discussion about moving responsibility for high-level SCTs out of the *what packages, so that people will use/modify a library that depends on testwhat instead to get high-level SCTs.