From 9083fc8a9dbb637e0a6cb0063a1cc440eeaa8d1f Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Thu, 22 Aug 2019 23:50:34 -0400 Subject: [PATCH] rename functions per #65 update docs and tests (#72) * Use roxygen markdown for comments, using roxygen2md::roxygen2md() * Use @inheritParams instead of @template, for cleaner documentation and less duplication * Convert remaining documentation entries to roxygen markdown; Reflow docs; Minor fixes. * rename functions per #65 update docs and tests * grader -> gradethis in badges in reademe * fix missed conflict block * fix things after rebase * Remove period in title * fix link * add parens * magrittr pipe link * magrittr pipe link * put back grade_conditions examples and regenerate docs --- NAMESPACE | 8 +-- R/condition.R | 2 +- R/evaluate_condition.R | 2 +- R/get_code.R | 2 +- R/{check_code.R => grade_code.R} | 26 +++---- R/{test_result.R => grade_conditions.R} | 17 +++-- R/grade_learnr.R | 4 +- R/{check_result.R => grade_result.R} | 12 ++-- R/{grading_demo.R => gradethis_demo.R} | 13 ++-- R/insert_exercise_check_code.R | 8 +-- R/pass_fail_if.R | 2 +- README.md | 24 ++++--- inst/rstudio/addins.dcf | 8 +-- inst/tutorials/grading-demo/grading-demo.Rmd | 34 ++++----- ...ult_examples.R => grade_result_examples.R} | 8 +-- man/condition.Rd | 10 +-- man/{check_code.Rd => grade_code.Rd} | 32 ++++----- man/{test_result.Rd => grade_conditions.Rd} | 22 +++--- man/grade_learnr.Rd | 4 +- man/{check_result.Rd => grade_result.Rd} | 22 +++--- man/{grading_demo.Rd => gradethis_demo.Rd} | 12 ++-- tests/testthat/test_check_code.R | 70 +++++++++---------- tests/testthat/test_check_result.R | 24 +++---- tests/testthat/test_check_result_df.R | 2 +- tests/testthat/test_check_result_message.R | 26 +++---- tests/testthat/test_grade_learnr.R | 8 +-- tests/testthat/test_test_result.R | 39 ----------- tests/testthat/test_test_result_message.R | 6 +- 28 files changed, 213 insertions(+), 234 deletions(-) rename R/{check_code.R => grade_code.R} (87%) rename R/{test_result.R => grade_conditions.R} (93%) rename R/{check_result.R => grade_result.R} (87%) rename R/{grading_demo.R => gradethis_demo.R} (68%) rename man-roxygen/{check_result_examples.R => grade_result_examples.R} (89%) rename man/{check_code.Rd => grade_code.Rd} (77%) rename man/{test_result.Rd => grade_conditions.Rd} (85%) rename man/{check_result.Rd => grade_result.Rd} (86%) rename man/{grading_demo.Rd => gradethis_demo.Rd} (72%) delete mode 100644 tests/testthat/test_test_result.R diff --git a/NAMESPACE b/NAMESPACE index 0f8eaff5..88dab937 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,16 +1,16 @@ # Generated by roxygen2: do not edit by hand -export(check_code) -export(check_result) export(condition) export(evaluate_condition) export(fail_if) +export(grade_code) +export(grade_conditions) export(grade_learnr) +export(grade_result) export(graded) -export(grading_demo) +export(gradethis_demo) export(pass_if) export(random_encourage) export(random_praise) -export(test_result) importFrom(rlang,"%||%") importFrom(utils,browseURL) diff --git a/R/condition.R b/R/condition.R index cb8cdda1..778d6f00 100644 --- a/R/condition.R +++ b/R/condition.R @@ -31,7 +31,7 @@ #' @export #' #' @examples -#' \dontrun{grading_demo()} +#' \dontrun{gradethis_demo()} #' #' condition(~ identical(x = .result, 5), message = "Correct", correct = TRUE) condition <- function(x, message, correct) { diff --git a/R/evaluate_condition.R b/R/evaluate_condition.R index 6e7c901b..c854b5ec 100644 --- a/R/evaluate_condition.R +++ b/R/evaluate_condition.R @@ -44,7 +44,7 @@ evaluate_condition <- function(condition, grader_args, learnr_args) { res <- !all(is.na(res)) && all(res, na.rm = TRUE) } - # implement when we add a `exec`/`expect` api to check_result + # implement when we add a `exec`/`expect` api to grade_result # will account for function returns # if (inherits(res, 'grader_graded')) {return(res)} # nolint if (is.null(res)) return(NULL) diff --git a/R/get_code.R b/R/get_code.R index 382c57aa..a2623d59 100644 --- a/R/get_code.R +++ b/R/get_code.R @@ -3,7 +3,7 @@ #' Helper methods around [rlang::eval_tidy()] #' to extract user code and solution code. #' -#' @seealso [check_result()], [test_result()], and [check_code()] +#' @seealso [grade_result()], [grade_conditions()], and [grade_code()] #' @param user,solution,expr An expression or quosure to evaluate. #' @param name Name to print if a `NULL` expression is provided. #' diff --git a/R/check_code.R b/R/grade_code.R similarity index 87% rename from R/check_code.R rename to R/grade_code.R index 8af84974..eb91a1bb 100644 --- a/R/check_code.R +++ b/R/grade_code.R @@ -1,29 +1,29 @@ -#' Check code against a solution +#' Grade code against a solution #' #' Checks the code expression or the code result against a solution. #' -#' `check_code()` compares student code to a solution (i.e. model code) and +#' `grade_code()` compares student code to a solution (i.e. model code) and #' describes the first way that the student code differs. If the student code -#' exactly matches the solution, `check_code()` returns a customizable success +#' exactly matches the solution, `grade_code()` returns a customizable success #' message (`correct`). If the student code does not match the solution, a #' customizable incorrect message (`incorrect`) can also be provided. #' -#' `check_code()` provides a *strict* check in that the student code must +#' `grade_code()` provides a *strict* check in that the student code must #' exactly match the solution. It is not enough for the student code to be #' equivalent to the solution code (e.g. to return the same result as the #' solution). #' -#' You can provide solution code for `check_code()` to use in two ways: +#' You can provide solution code for `grade_code()` to use in two ways: #' #' 1. Pass code as a character string or a quoted expression to the solution -#' argument of `check_code()` +#' argument of `grade_code()` #' #' 2. Make a "-solution" code chunk for the exercise to be checked in a learnr -#' document. There is no need to supply a solution argument for `check_code()` +#' document. There is no need to supply a solution argument for `grade_code()` #' if you call it from the "-check" chunk of the same exercise. Likewise, there #' is no need to supply a student submitted code argument when you call -#' `check_code()` from a learnr document (learnr will provide the code that the -#' student submits when it runs `check_code()`. +#' `grade_code()` from a learnr document (learnr will provide the code that the +#' student submits when it runs `grade_code()`. #' #' For best results, name all arguments provided in the solution code. #' @@ -61,16 +61,16 @@ #' that the answer differs, the message will be the content of the `glue_pipe` #' argument. #' -#' @seealso [check_code()], [check_result()], and [test_result()] +#' @seealso [grade_code()], [grade_result()], and [grade_conditions()] #' @export #' @examples -#' \dontrun{grading_demo()} +#' \dontrun{gradethis_demo()} #' #' # This is a manual example, see grading demo for `learnr` tutorial usage #' y <- quote(sqrt(log(2))) #' z <- quote(sqrt(log(1))) -#' check_code(grader_args = list(user_quo = y, solution_quo = z)) -check_code <- function( +#' grade_code(grader_args = list(user_quo = y, solution_quo = z)) +grade_code <- function( correct = NULL, incorrect = NULL, grader_args = list(), diff --git a/R/test_result.R b/R/grade_conditions.R similarity index 93% rename from R/test_result.R rename to R/grade_conditions.R index c1ae3a3e..fa595a39 100644 --- a/R/test_result.R +++ b/R/grade_conditions.R @@ -1,10 +1,14 @@ -#' Test the result of exercise code +#' Grade all specified conditions #' #' Executes tests against the final result of the user code. If #' a test throws an error, the test fails and the submitted answer will be #' marked incorrect. #' -#' @inheritParams check_code +#' Executes tests against the final result of the user code. If +#' a test throws an error, the test fails and the submitted answer will be +#' marked incorrect. +#' +#' @inheritParams grade_code #' #' @param correct A character string to display if all tests pass. This #' character string will be run through [glue::glue_data] with: @@ -32,25 +36,26 @@ #' @seealso `test` #' @export #' @examples -#' \dontrun{grading_demo()} +#' \dontrun{gradethis_demo()} #' #' example_function <- function(x){ #' return(x + 1) #' } -#' test_result( +#' grade_conditions( #' pass_if(~ .result(3) == 4), #' pass_if(~ .result(10) == 11), #' grader_args = list(), #' learnr_args = list(last_value = example_function, envir_prep = new.env()) #' ) #' -#' test_result( +#' grade_conditions( #' pass_if(~ .result(3) == 4), #' fail_if(~ .result(10) == 11), #' grader_args = list(), #' learnr_args = list(last_value = example_function, envir_prep = new.env()) #' ) -test_result <- function( +#' +grade_conditions <- function( ..., correct = NULL, incorrect = NULL, diff --git a/R/grade_learnr.R b/R/grade_learnr.R index b7f2c4f5..a78a560a 100644 --- a/R/grade_learnr.R +++ b/R/grade_learnr.R @@ -13,7 +13,7 @@ #' `tutorial_options(exercise.checker = grade_learnr)` in the setup chunk #' of your tutorial. #' -#' Run `grading_demo()` to see an example learnr document that uses +#' Run `gradethis_demo()` to see an example learnr document that uses #' `grade_learnr()`. #' #' @param label Label for exercise chunk @@ -34,7 +34,7 @@ #' @export #' #' @examples -#' \dontrun{grading_demo()} +#' \dontrun{gradethis_demo()} grade_learnr <- function(label = NULL, solution_code = NULL, user_code = NULL, diff --git a/R/check_result.R b/R/grade_result.R similarity index 87% rename from R/check_result.R rename to R/grade_result.R index 2fe9f29b..e53a3d27 100644 --- a/R/check_result.R +++ b/R/grade_result.R @@ -1,10 +1,10 @@ -#' Check result of exercise code. +#' Grade result of exercise code #' #' Compares the final result of the student code to known [pass_if()] and #' [fail_if()] [condition()]s. If the student result exactly matches a known #' case, returns the matching message value. #' -#' @inheritParams check_code +#' @inheritParams grade_code #' #' @param ... [pass_if()] or [fail_if()] [condition()]s to check #' @@ -12,13 +12,13 @@ #' a formatted `correct` or `incorrect` message and whether or not a match was #' found. #' -#' @seealso [check_code()], [check_result()], and [test_result()] +#' @seealso [grade_code()], [grade_result()], and [grade_conditions()] #' @export #' @examples -#' \dontrun{grading_demo()} +#' \dontrun{gradethis_demo()} #' -#' @template check_result_examples -check_result <- function( +#' @template grade_result_examples +grade_result <- function( ..., correct = NULL, incorrect = NULL, diff --git a/R/grading_demo.R b/R/gradethis_demo.R similarity index 68% rename from R/grading_demo.R rename to R/gradethis_demo.R index 34e2031a..a8ded9a5 100644 --- a/R/grading_demo.R +++ b/R/gradethis_demo.R @@ -1,13 +1,13 @@ #' Grading Demo #' -#' If you are using the RStudio IDE, `grading_demo()` opens an example learnr +#' If you are using the RStudio IDE, `gradethis_demo()` opens an example learnr #' file that demonstrates how to use the grader package to check student code. #' #' The tutorial sets the learnr `exercise.checker` option to #' `grade_learnr()` in the document's setup chunk. #' #' It then uses three different exercise checking methods: -#' [check_result()], [test_result()], and [check_code()]. +#' [grade_result()], [grade_conditions()], and [grade_code()]. #' #' To use a checking method, follow the exercise chunk with a chunk whose label #' matches the label of the exercise chunk (ex: `myexercise`) but includes the suffix @@ -21,11 +21,12 @@ #' #' @export #' @importFrom utils browseURL -grading_demo <- function() { - grading_demo_path <- system.file("tutorials", "grading-demo/grading-demo.Rmd", package = "grader") +gradethis_demo <- function() { + gradethis_demo_path <- system.file("tutorials", "grading-demo/grading-demo.Rmd", + package = "grader") if (rstudioapi::isAvailable()) { - rstudioapi::navigateToFile(grading_demo_path) + rstudioapi::navigateToFile(gradethis_demo_path) } else { - browseURL(paste0("file://", grading_demo_path)) + browseURL(paste0("file://", gradethis_demo_path)) } } diff --git a/R/insert_exercise_check_code.R b/R/insert_exercise_check_code.R index f5e2202e..ff69e0b8 100644 --- a/R/insert_exercise_check_code.R +++ b/R/insert_exercise_check_code.R @@ -1,4 +1,4 @@ -insert_exercise_check_code <- function() { +insert_exercise_grade_code <- function() { random_chunk_label <- generate_random_chunk_label() # nolint start @@ -25,13 +25,13 @@ ____ ```{r <>-check} # check code -gradethis::check_code() +gradethis::grade_code() ``` " , .open = "<<", .close = ">>")) # nolint end } -insert_exercise_check_result <- function() { +insert_exercise_grade_result <- function() { random_chunk_label <- generate_random_chunk_label() # nolint start @@ -52,7 +52,7 @@ ____ ``` ```{r <>-check} -gradethis::check_result( +gradethis::grade_result( gradethis::pass_if(~ identical(.result, 1), \"YAY!\"), gradethis::fail_if(~ identical(.result, 2), \"Try Again.\") ) diff --git a/R/pass_fail_if.R b/R/pass_fail_if.R index 6685cd6d..20db38f2 100644 --- a/R/pass_fail_if.R +++ b/R/pass_fail_if.R @@ -9,7 +9,7 @@ #' a condition that if matched means the student provided result is correct #' #' @export -#' @template check_result_examples +#' @template grade_result_examples pass_if <- function(x, message = NULL) { condition(x, message, correct = TRUE) } diff --git a/README.md b/README.md index 7efc69f2..3b151064 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,37 @@ -# grader +# gradethis -[![Travis build status](https://travis-ci.org/rstudio-education/grader.svg?branch=master)](https://travis-ci.org/rstudio-education/grader) -[![Codecov test coverage](https://codecov.io/gh/rstudio-education/grader/branch/master/graph/badge.svg)](https://codecov.io/gh/rstudio-education/grader?branch=master) -[![CRAN version](http://www.r-pkg.org/badges/version/grader)](https://cran.r-project.org/package=grader) -[![grader downloads per month](http://cranlogs.r-pkg.org/badges/grader)](http://www.rpackages.io/package/grader) +[![Travis build status](https://travis-ci.org/rstudio-education/gradethis.svg?branch=master)](https://travis-ci.org/rstudio-education/gradethis) +[![Codecov test coverage](https://codecov.io/gh/rstudio-education/gradethis/branch/master/graph/badge.svg)](https://codecov.io/gh/rstudio-education/gradethis?branch=master) +[![CRAN version](http://www.r-pkg.org/badges/version/gradethis)](https://cran.r-project.org/package=gradethis) +[![gradethis downloads per month](http://cranlogs.r-pkg.org/badges/gradethis)](http://www.rpackages.io/package/gradethis) [![DOI](https://zenodo.org/badge/126734088.svg)](https://zenodo.org/badge/latestdoi/126734088) [![RStudio Community: Teaching](https://img.shields.io/badge/Community%20Support-Teaching-75aadb.svg?style=popout&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiCgkgdmlld0JveD0iMCAwIDYyNS45IDYyNS45IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA2MjUuOSA2MjUuOTsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiM3NUFBREI7fQoJLnN0MXtmaWxsOiM0RDRENEQ7fQoJLnN0MntmaWxsOiNGRkZGRkY7fQoJLnN0M3tmaWxsOnVybCgjU1ZHSURfMV8pO30KCS5zdDR7ZmlsbDp1cmwoI1NWR0lEXzJfKTt9Cgkuc3Q1e2ZpbGw6dXJsKCNTVkdJRF8zXyk7fQoJLnN0Nnt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+)](https://community.rstudio.com/new-topic?title=&category_id=13&tags=grader&body=%0A%0A%0A%20%20--------%0A%20%20%0A%20%20%3Csup%3EReferred%20here%20by%20%60grader%60%27s%20README%3C/sup%3E%0A&u=barret) +[![RStudio Ask a question: gradethis](https://img.shields.io/badge/Ask%20a%20question-gradethis-75aadb.svg?style=popout&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNjI1LjkgNjI1LjkiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDYyNS45IDYyNS45OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+Cgkuc3Qwe2ZpbGw6Izc1QUFEQjt9Cgkuc3Qxe2ZpbGw6IzRENEQ0RDt9Cgkuc3Qye2ZpbGw6I0ZGRkZGRjt9Cgkuc3Qze2ZpbGw6dXJsKCNTVkdJRF8xXyk7fQoJLnN0NHtmaWxsOnVybCgjU1ZHSURfMl8pO30KCS5zdDV7ZmlsbDp1cmwoI1NWR0lEXzNfKTt9Cgkuc3Q2e2ZpbGw6dXJsKCNTVkdJRF80Xyk7fQoJLnN0N3tmaWxsOnVybCgjU1ZHSURfNV8pO30KCS5zdDh7ZmlsbDp1cmwoI1NWR0lEXzZfKTt9Cgkuc3Q5e2ZpbGw6dXJsKCNTVkdJRF83Xyk7fQoJLnN0MTB7ZmlsbDp1cmwoI1NWR0lEXzhfKTt9Cgkuc3QxMXtmaWxsOnVybCgjU1ZHSURfOV8pO30KCS5zdDEye2ZpbGw6dXJsKCNTVkdJRF8xMF8pO30KCS5zdDEze29wYWNpdHk6MC4xODtmaWxsOnVybCgjU1ZHSURfMTFfKTt9Cgkuc3QxNHtvcGFjaXR5OjAuMzt9Cjwvc3R5bGU+CjxnIGlkPSJHcmF5X0xvZ28iPgo8L2c+CjxnIGlkPSJCbGFja19MZXR0ZXJzIj4KPC9nPgo8ZyBpZD0iQmx1ZV9HcmFkaWVudF9MZXR0ZXJzIj4KCTxnPgoKCQkJPGVsbGlwc2UgdHJhbnNmb3JtPSJtYXRyaXgoMC43MDcxIC0wLjcwNzEgMC43MDcxIDAuNzA3MSAtMTI3LjkyNjUgMzE3LjAzMTcpIiBjbGFzcz0ic3QwIiBjeD0iMzE4LjciIGN5PSIzMTIuOSIgcng9IjMwOS44IiByeT0iMzA5LjgiLz4KCQk8Zz4KCQkJPHBhdGggY2xhc3M9InN0MiIgZD0iTTQyNC43LDQxMS44aDMzLjZ2MjYuMWgtNTEuM0wzMjIsMzEwLjVoLTQ1LjN2MTAxLjNoNDQuM3YyNi4xSDIwOS41di0yNi4xaDM4LjNWMTg3LjNsLTM4LjMtNC43di0yNC43ICAgICBjMTQuNSwzLjMsMjcuMSw1LjYsNDIuOSw1LjZjMjMuOCwwLDQ4LjEtNS42LDcxLjktNS42YzQ2LjIsMCw4OS4xLDIxLDg5LjEsNzIuM2MwLDM5LjctMjMuOCw2NC45LTYwLjcsNzUuNkw0MjQuNyw0MTEuOHogICAgICBNMjc2LjcsMjg1LjNsMjQuMywwLjVjNTkuMywwLjksODIuMS0yMS45LDgyLjEtNTIuM2MwLTM1LjUtMjUuNy00OS41LTU4LjMtNDkuNWMtMTUuNCwwLTMxLjMsMS40LTQ4LjEsMy4zVjI4NS4zeiIvPgoJCTwvZz4KCTwvZz4KPC9nPgo8ZyBpZD0iV2hpdGVfTGV0dGVycyI+CjwvZz4KPGcgaWQ9IlJfQmFsbCI+CjwvZz4KPC9zdmc+)](https://community.rstudio.com/new-topic?title=&category_id=13&tags=gradethis&body=%0A%0A%0A%20%20--------%0A%20%20%0A%20%20%3Csup%3EReferred%20here%20by%20%60gradethis%60%27s%20README%3C/sup%3E%0A&u=barret) -Pairing with the `learnr` R package, `grader` provides multiple methods to grade `learnr` exercises. To learn more about `learnr` tutorials, please visit [https://rstudio.github.io/learnr/](https://rstudio.github.io/learnr/). +Pairing with the `learnr` R package, `gradethis` provides multiple methods to grade `learnr` exercises. To learn more about `learnr` tutorials, please visit [https://rstudio.github.io/learnr/](https://rstudio.github.io/learnr/). ## Installation -You can install the released version of grader from [CRAN](https://CRAN.R-project.org) with: +You can install the released version of gradethis from [CRAN](https://CRAN.R-project.org) with: ``` r install.packages("gradethis") ``` +The development version of `gradethis` can be installed from GitHub with: + +```r +remotes::install_github("rstudio-education/gradethis") +``` + ## Grading Demo To view the latest grading demo of the different checking methods: ``` r library(gradethis) -gradethis::grading_demo() +gradethis::gradethis_demo()) ``` diff --git a/inst/rstudio/addins.dcf b/inst/rstudio/addins.dcf index fac772ce..30afceb8 100644 --- a/inst/rstudio/addins.dcf +++ b/inst/rstudio/addins.dcf @@ -1,9 +1,9 @@ -Name: Insert exercise: check code +Name: Insert exercise: grade code Description: Inserts code chunks to do code checking at the cursor position. -Binding: insert_exercise_check_code +Binding: insert_exercise_grade_code Interactive: false -Name: Insert exercise: check result +Name: Insert exercise: grade result/conditions Description: Inserts code chunks to do result checking at the cursor position. -Binding: insert_exercise_check_result +Binding: insert_exercise_grade_result_conditions Interactive: false diff --git a/inst/tutorials/grading-demo/grading-demo.Rmd b/inst/tutorials/grading-demo/grading-demo.Rmd index faba9023..4a53cea3 100644 --- a/inst/tutorials/grading-demo/grading-demo.Rmd +++ b/inst/tutorials/grading-demo/grading-demo.Rmd @@ -22,7 +22,7 @@ knitr::opts_chunk$set(echo = FALSE) `gradethis` can check for the final returned value. This grading approach does not inspect the code. It only inspects the final result. -See `?check_result` for more information. +See `?grade_result` for more information. Example code written below: @@ -40,7 +40,7 @@ Example code written below: ``` `r ''````{r result-check} -check_result( +grade_result( results( result(1, "Custom message for value 1."), result(2, "Custom message for value 2.", correct = TRUE), @@ -68,7 +68,7 @@ check_result( ``` ```{r result-check} -check_result( +grade_result( result(1, "Custom message for value 1."), result(2, "Custom message for value 2.", correct = TRUE), result(3, "Custom message for value 3."), @@ -80,31 +80,31 @@ check_result( `gradethis` can test against for the final returned value. This grading approach does not inspect the code. It only inspects the final result. -Writers can include as many testing functions as they would like. The test functions should accept a single result value to test against. If any test fails, it should throw an error. This error message will be returned back to the user by default. See `?test_result` for more information. +Writers can include as many testing functions as they would like. The test functions should accept a single result value to test against. If any test fails, it should throw an error. This error message will be returned back to the user by default. See `?grade_conditions` for more information. Example code written below: ````markdown -`r ''````{r test_result, exercise = TRUE} +`r ''````{r grade_conditions, exercise = TRUE} function(x) { sqrt(log(x)) } ``` -`r ''````{r test_result-hint-1} +`r ''````{r grade_conditions-hint-1} "function(x) { sqrt(...) }" ``` -`r ''````{r test_result-hint-2} +`r ''````{r grade_conditions-hint-2} "function(x) { sqrt(log(...)) }" ``` -`r ''````{r test_result-check} -test_result( +`r ''````{r grade_conditions-check} +grade_conditions( tests( function(your_answer) { checkmate::expect_function(your_answer, args = c("x")) @@ -138,26 +138,26 @@ Please make a function in the exercise space below. It should: Then click Submit Answer. -```{r test_result, exercise = TRUE} +```{r grade_conditions, exercise = TRUE} function(x) { sqrt(log(x)) } ``` -```{r test_result-hint-1} +```{r grade_conditions-hint-1} "function(x) { sqrt(...) }" ``` -```{r test_result-hint-2} +```{r grade_conditions-hint-2} "function(x) { sqrt(log(...)) }" ``` -```{r test_result-check} -test_result( +```{r grade_conditions-check} +grade_conditions( tests( function(your_answer) { checkmate::expect_function(your_answer, args = c("x")) @@ -186,7 +186,7 @@ test_result( This check method requires a `*-solution` code chunk containing the solution to compare. Only the last solution expression and last user expression will be matched. -See `?check_code` for more information. +See `?grade_code` for more information. Example code written below: @@ -208,7 +208,7 @@ sqrt(log(2)) ``` `r ''````{r strict-check} -check_code("Good job. Don't worry, things will soon get harder.") +grade_code("Good job. Don't worry, things will soon get harder.") ``` ```` @@ -237,7 +237,7 @@ sqrt(log(2)) ``` ```{r strict-check} -check_code("Good job. Don't worry, things will soon get harder.") +grade_code("Good job. Don't worry, things will soon get harder.") ``` diff --git a/man-roxygen/check_result_examples.R b/man-roxygen/grade_result_examples.R similarity index 89% rename from man-roxygen/check_result_examples.R rename to man-roxygen/grade_result_examples.R index c7f58236..3199228c 100644 --- a/man-roxygen/check_result_examples.R +++ b/man-roxygen/grade_result_examples.R @@ -1,21 +1,21 @@ #' @examples -#' check_result( +#' grade_result( #' pass_if(~ identical(.result, 5), "This is a correct message"), #' grader_args = list(), #' learnr_args = list(last_value = 5, envir_prep = new.env()) #' ) #' -#' check_result( +#' grade_result( #' pass_if(function(x) identical(x, 5), "This is a correct message"), #' learnr_args = list(last_value = 5) #' ) #' -#' check_result( +#' grade_result( #' pass_if(5, "This is a correct message"), #' learnr_args = list(last_value = 5) #' ) #' -#' check_result( +#' grade_result( #' fail_if(5, "You were supposed to do this other thing!"), #' pass_if(~ TRUE, "should never reach here"), #' learnr_args = list(last_value = 5) diff --git a/man/condition.Rd b/man/condition.Rd index 15545073..2419070d 100644 --- a/man/condition.Rd +++ b/man/condition.Rd @@ -55,26 +55,26 @@ correct status, and condition type }} \examples{ -\dontrun{grading_demo()} +\dontrun{gradethis_demo()} condition(~ identical(x = .result, 5), message = "Correct", correct = TRUE) -check_result( +grade_result( pass_if(~ identical(.result, 5), "This is a correct message"), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) ) -check_result( +grade_result( pass_if(function(x) identical(x, 5), "This is a correct message"), learnr_args = list(last_value = 5) ) -check_result( +grade_result( pass_if(5, "This is a correct message"), learnr_args = list(last_value = 5) ) -check_result( +grade_result( fail_if(5, "You were supposed to do this other thing!"), pass_if(~ TRUE, "should never reach here"), learnr_args = list(last_value = 5) diff --git a/man/check_code.Rd b/man/grade_code.Rd similarity index 77% rename from man/check_code.Rd rename to man/grade_code.Rd index c0c36567..f13cd12c 100644 --- a/man/check_code.Rd +++ b/man/grade_code.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/check_code.R -\name{check_code} -\alias{check_code} -\title{Check code against a solution} +% Please edit documentation in R/grade_code.R +\name{grade_code} +\alias{grade_code} +\title{Grade code against a solution} \usage{ -check_code(correct = NULL, incorrect = NULL, grader_args = list(), +grade_code(correct = NULL, incorrect = NULL, grader_args = list(), learnr_args = list(), glue_correct = getOption("gradethis_glue_correct"), glue_incorrect = getOption("gradethis_glue_incorrect"), @@ -50,39 +50,39 @@ argument. Checks the code expression or the code result against a solution. } \details{ -\code{check_code()} compares student code to a solution (i.e. model code) and +\code{grade_code()} compares student code to a solution (i.e. model code) and describes the first way that the student code differs. If the student code -exactly matches the solution, \code{check_code()} returns a customizable success +exactly matches the solution, \code{grade_code()} returns a customizable success message (\code{correct}). If the student code does not match the solution, a customizable incorrect message (\code{incorrect}) can also be provided. -\code{check_code()} provides a \emph{strict} check in that the student code must +\code{grade_code()} provides a \emph{strict} check in that the student code must exactly match the solution. It is not enough for the student code to be equivalent to the solution code (e.g. to return the same result as the solution). -You can provide solution code for \code{check_code()} to use in two ways: +You can provide solution code for \code{grade_code()} to use in two ways: \enumerate{ \item Pass code as a character string or a quoted expression to the solution -argument of \code{check_code()} +argument of \code{grade_code()} \item Make a "-solution" code chunk for the exercise to be checked in a learnr -document. There is no need to supply a solution argument for \code{check_code()} +document. There is no need to supply a solution argument for \code{grade_code()} if you call it from the "-check" chunk of the same exercise. Likewise, there is no need to supply a student submitted code argument when you call -\code{check_code()} from a learnr document (learnr will provide the code that the -student submits when it runs \code{check_code()}. +\code{grade_code()} from a learnr document (learnr will provide the code that the +student submits when it runs \code{grade_code()}. } For best results, name all arguments provided in the solution code. } \examples{ -\dontrun{grading_demo()} +\dontrun{gradethis_demo()} # This is a manual example, see grading demo for `learnr` tutorial usage y <- quote(sqrt(log(2))) z <- quote(sqrt(log(1))) -check_code(grader_args = list(user_quo = y, solution_quo = z)) +grade_code(grader_args = list(user_quo = y, solution_quo = z)) } \seealso{ -\code{\link[=check_code]{check_code()}}, \code{\link[=check_result]{check_result()}}, and \code{\link[=test_result]{test_result()}} +\code{\link[=grade_code]{grade_code()}}, \code{\link[=grade_result]{grade_result()}}, and \code{\link[=grade_conditions]{grade_conditions()}} } diff --git a/man/test_result.Rd b/man/grade_conditions.Rd similarity index 85% rename from man/test_result.Rd rename to man/grade_conditions.Rd index afe3dea5..e6915325 100644 --- a/man/test_result.Rd +++ b/man/grade_conditions.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/test_result.R -\name{test_result} -\alias{test_result} -\title{Test the result of exercise code} +% Please edit documentation in R/grade_conditions.R +\name{grade_conditions} +\alias{grade_conditions} +\title{Grade all specified conditions} \usage{ -test_result(..., correct = NULL, incorrect = NULL, +grade_conditions(..., correct = NULL, incorrect = NULL, grader_args = list(), learnr_args = list(), glue_correct = getOption("gradethis_glue_correct_test"), glue_incorrect = getOption("gradethis_glue_incorrect_test")) @@ -57,25 +57,31 @@ Executes tests against the final result of the user code. If a test throws an error, the test fails and the submitted answer will be marked incorrect. } +\details{ +Executes tests against the final result of the user code. If +a test throws an error, the test fails and the submitted answer will be +marked incorrect. +} \examples{ -\dontrun{grading_demo()} +\dontrun{gradethis_demo()} example_function <- function(x){ return(x + 1) } -test_result( +grade_conditions( pass_if(~ .result(3) == 4), pass_if(~ .result(10) == 11), grader_args = list(), learnr_args = list(last_value = example_function, envir_prep = new.env()) ) -test_result( +grade_conditions( pass_if(~ .result(3) == 4), fail_if(~ .result(10) == 11), grader_args = list(), learnr_args = list(last_value = example_function, envir_prep = new.env()) ) + } \seealso{ \code{test} diff --git a/man/grade_learnr.Rd b/man/grade_learnr.Rd index ebfd4d85..010670a2 100644 --- a/man/grade_learnr.Rd +++ b/man/grade_learnr.Rd @@ -49,9 +49,9 @@ To enable exercise checking in your learnr tutorial, set \code{tutorial_options(exercise.checker = grade_learnr)} in the setup chunk of your tutorial. -Run \code{grading_demo()} to see an example learnr document that uses +Run \code{gradethis_demo()} to see an example learnr document that uses \code{grade_learnr()}. } \examples{ -\dontrun{grading_demo()} +\dontrun{gradethis_demo()} } diff --git a/man/check_result.Rd b/man/grade_result.Rd similarity index 86% rename from man/check_result.Rd rename to man/grade_result.Rd index 1448f149..7bca8940 100644 --- a/man/check_result.Rd +++ b/man/grade_result.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/check_result.R -\name{check_result} -\alias{check_result} -\title{Check result of exercise code.} +% Please edit documentation in R/grade_result.R +\name{grade_result} +\alias{grade_result} +\title{Grade result of exercise code} \usage{ -check_result(..., correct = NULL, incorrect = NULL, +grade_result(..., correct = NULL, incorrect = NULL, grader_args = list(), learnr_args = list(), glue_correct = getOption("gradethis_glue_correct"), glue_incorrect = getOption("gradethis_glue_incorrect")) @@ -49,30 +49,30 @@ Compares the final result of the student code to known \code{\link[=pass_if]{pas case, returns the matching message value. } \examples{ -\dontrun{grading_demo()} +\dontrun{gradethis_demo()} -check_result( +grade_result( pass_if(~ identical(.result, 5), "This is a correct message"), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) ) -check_result( +grade_result( pass_if(function(x) identical(x, 5), "This is a correct message"), learnr_args = list(last_value = 5) ) -check_result( +grade_result( pass_if(5, "This is a correct message"), learnr_args = list(last_value = 5) ) -check_result( +grade_result( fail_if(5, "You were supposed to do this other thing!"), pass_if(~ TRUE, "should never reach here"), learnr_args = list(last_value = 5) ) } \seealso{ -\code{\link[=check_code]{check_code()}}, \code{\link[=check_result]{check_result()}}, and \code{\link[=test_result]{test_result()}} +\code{\link[=grade_code]{grade_code()}}, \code{\link[=grade_result]{grade_result()}}, and \code{\link[=grade_conditions]{grade_conditions()}} } diff --git a/man/grading_demo.Rd b/man/gradethis_demo.Rd similarity index 72% rename from man/grading_demo.Rd rename to man/gradethis_demo.Rd index ebacc0fc..29a3e31a 100644 --- a/man/grading_demo.Rd +++ b/man/gradethis_demo.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/grading_demo.R -\name{grading_demo} -\alias{grading_demo} +% Please edit documentation in R/gradethis_demo.R +\name{gradethis_demo} +\alias{gradethis_demo} \title{Grading Demo} \usage{ -grading_demo() +gradethis_demo() } \description{ -If you are using the RStudio IDE, \code{grading_demo()} opens an example learnr +If you are using the RStudio IDE, \code{gradethis_demo()} opens an example learnr file that demonstrates how to use the grader package to check student code. } \details{ @@ -15,7 +15,7 @@ The tutorial sets the learnr \code{exercise.checker} option to \code{grade_learnr()} in the document's setup chunk. It then uses three different exercise checking methods: -\code{\link[=check_result]{check_result()}}, \code{\link[=test_result]{test_result()}}, and \code{\link[=check_code]{check_code()}}. +\code{\link[=grade_result]{grade_result()}}, \code{\link[=grade_conditions]{grade_conditions()}}, and \code{\link[=grade_code]{grade_code()}}. To use a checking method, follow the exercise chunk with a chunk whose label matches the label of the exercise chunk (ex: \code{myexercise}) but includes the suffix diff --git a/tests/testthat/test_check_code.R b/tests/testthat/test_check_code.R index 2af680d5..c60eaf77 100644 --- a/tests/testthat/test_check_code.R +++ b/tests/testthat/test_check_code.R @@ -8,13 +8,13 @@ test_that("Spots differences in atomics", { solution <- quote(1) expect_correct( - check_code(grader_args = list(user_quo = user, solution_quo = solution)) + grade_code(grader_args = list(user_quo = user, solution_quo = solution)) ) user <- quote(1) solution <- quote(2) expect_message( - check_code(grader_args = list(user_quo = user, solution_quo = solution)), + grade_code(grader_args = list(user_quo = user, solution_quo = solution)), wrong_value(this = quote(1), that = quote(2)) ) }) @@ -24,20 +24,20 @@ test_that("Spots differences in names", { user <- quote(x) solution <- quote(y) expect_message( - check_code(grader_args = list(user_quo = user, solution_quo = solution)), + grade_code(grader_args = list(user_quo = user, solution_quo = solution)), wrong_value(this = quote(x), that = quote(y)) ) user <- quote(x) solution <- quote(x) expect_correct( - check_code(grader_args = list(user_quo = user, solution_quo = solution)) + grade_code(grader_args = list(user_quo = user, solution_quo = solution)) ) user <- quote(5) solution <- quote(y) expect_message( - check_code(grader_args = list(user_quo = user, solution_quo = solution)), + grade_code(grader_args = list(user_quo = user, solution_quo = solution)), wrong_value(this = quote(5), that = quote(y)) ) }) @@ -49,23 +49,23 @@ test_that("Spots differences in calls", { d <- quote(vapply(vecs, mean, numeric(1))) expect_correct( - check_code(grader_args = list(user_quo = a, solution_quo = a)) + grade_code(grader_args = list(user_quo = a, solution_quo = a)) ) expect_message( - check_code(grader_args = list(user_quo = a, solution_quo = b)), + grade_code(grader_args = list(user_quo = a, solution_quo = b)), wrong_value(this = quote(lists), that = quote(vecs)) ) expect_message( - check_code(grader_args = list(user_quo = a, solution_quo = c)), + grade_code(grader_args = list(user_quo = a, solution_quo = c)), surplus_argument(this_call = "vapply()", this_name = "na.rm", this = quote(TRUE)) ) expect_message( - check_code(grader_args = list(user_quo = c, solution_quo = a)), + grade_code(grader_args = list(user_quo = c, solution_quo = a)), missing_argument(this_call = "vapply()", that_name = "na.rm", that = quote(TRUE)) @@ -79,21 +79,21 @@ test_that("Mentions only first non-matching element", { z <- quote(sqrt(log(1))) expect_correct( - check_code(grader_args = list(user_quo = w, solution_quo = w)) + grade_code(grader_args = list(user_quo = w, solution_quo = w)) ) expect_message( - check_code(grader_args = list(user_quo = w, solution_quo = z)), + grade_code(grader_args = list(user_quo = w, solution_quo = z)), wrong_value(this = quote(1), that = quote(sqrt())) ) expect_message( - check_code(grader_args = list(user_quo = x, solution_quo = z)), + grade_code(grader_args = list(user_quo = x, solution_quo = z)), wrong_value(this = "log(1)", that = quote(sqrt())) ) expect_message( - check_code(grader_args = list(user_quo = y, solution_quo = z)), + grade_code(grader_args = list(user_quo = y, solution_quo = z)), wrong_value(this = "2", that = quote(1)) ) @@ -105,15 +105,15 @@ test_that("Spots differences in argument names", { c <- quote(mean(1:10, cut = 1, na.rm = TRUE)) expect_correct( - check_code(grader_args = list(user_quo = a, solution_quo = a)) + grade_code(grader_args = list(user_quo = a, solution_quo = a)) ) expect_correct( - check_code(grader_args = list(user_quo = b, solution_quo = a)) + grade_code(grader_args = list(user_quo = b, solution_quo = a)) ) expect_message( - check_code(grader_args = list(user_quo = c, solution_quo = a)), + grade_code(grader_args = list(user_quo = c, solution_quo = a)), wrong_value(this = quote(1), this_name = "cut", that = quote(1), that_name = "trim") ) @@ -127,19 +127,19 @@ test_that("Ignore differences in argument positions (for non ... arguments)", { d <- quote(round(digits = 2, x = pi)) expect_correct( - check_code(grader_args = list(user_quo = b, solution_quo = a)) + grade_code(grader_args = list(user_quo = b, solution_quo = a)) ) expect_correct( - check_code(grader_args = list(user_quo = c, solution_quo = a)) + grade_code(grader_args = list(user_quo = c, solution_quo = a)) ) expect_correct( - check_code(grader_args = list(user_quo = d, solution_quo = a)) + grade_code(grader_args = list(user_quo = d, solution_quo = a)) ) expect_correct( - check_code(grader_args = list(user_quo = a, solution_quo = d)) + grade_code(grader_args = list(user_quo = a, solution_quo = d)) ) }) @@ -147,7 +147,7 @@ test_that("Ignore differences in argument positions (for non ... arguments)", { test_that("Returns intelligent error when no solution code", { testthat::expect_error( - check_code(), + grade_code(), "No solution is provided for this exercise." ) @@ -155,7 +155,7 @@ test_that("Returns intelligent error when no solution code", { test_that("Returns intelligent error when no user code", { testthat::expect_error( - check_code(grader_args = list(solution_quo = quote(5))), + grade_code(grader_args = list(solution_quo = quote(5))), "I didn't receive your code. Did you write any?" ) }) @@ -164,7 +164,7 @@ test_that("Empty user solution messages", { grader_args <- list() learnr_args <- list() - testthat::expect_error(check_code(grader_args = grader_args, learnr_args = learnr_args), + testthat::expect_error(grade_code(grader_args = grader_args, learnr_args = learnr_args), "No solution is provided for this exercise.") }) @@ -184,16 +184,16 @@ test_that("Spot differences when pipes are involved", { pipe3 <- quote(iris %>% lm(Sepal.Length ~ Sepal.Width, data = .)) func3 <- quote(lm(Sepal.Length ~ Sepal.Width, data = iris)) - expect_correct(check_code(grader_args = list(user_quo = func, solution_quo = pipe))) - expect_correct(check_code(grader_args = list(user_quo = func1, solution_quo = pipe))) - expect_correct(check_code(grader_args = list(user_quo = pipe, solution_quo = func))) - expect_correct(check_code(grader_args = list(user_quo = pipe, solution_quo = func1))) - expect_correct(check_code(grader_args = list(user_quo = pipe, solution_quo = pipe))) - expect_correct(check_code(grader_args = list(user_quo = func, solution_quo = func1))) - expect_correct(check_code(grader_args = list(user_quo = func1, solution_quo = func1))) - expect_correct(check_code(grader_args = list(user_quo = func3, solution_quo = pipe3))) - expect_correct(check_code(grader_args = list(user_quo = pipe3, solution_quo = func3))) - expect_correct(check_code(grader_args = list(user_quo = pipe3, solution_quo = pipe3))) + expect_correct(grade_code(grader_args = list(user_quo = func, solution_quo = pipe))) + expect_correct(grade_code(grader_args = list(user_quo = func1, solution_quo = pipe))) + expect_correct(grade_code(grader_args = list(user_quo = pipe, solution_quo = func))) + expect_correct(grade_code(grader_args = list(user_quo = pipe, solution_quo = func1))) + expect_correct(grade_code(grader_args = list(user_quo = pipe, solution_quo = pipe))) + expect_correct(grade_code(grader_args = list(user_quo = func, solution_quo = func1))) + expect_correct(grade_code(grader_args = list(user_quo = func1, solution_quo = func1))) + expect_correct(grade_code(grader_args = list(user_quo = func3, solution_quo = pipe3))) + expect_correct(grade_code(grader_args = list(user_quo = pipe3, solution_quo = func3))) + expect_correct(grade_code(grader_args = list(user_quo = pipe3, solution_quo = pipe3))) }) @@ -204,12 +204,12 @@ test_that("Spots differences in long calls", { user <- rlang::sym("tidyr::gather(key = key, value = value, new_sp_m014:newrel_f65, na.rm = TRUE)") # nolint solution <- rlang::sym("tidyr::gather(key = key, value = value, new_sp_m014:newrel_f65, na.rm = FALSE)") # nolint expect_wrong( - check_code(grader_args = list(user_quo = user, solution_quo = solution)) + grade_code(grader_args = list(user_quo = user, solution_quo = solution)) ) user <- rlang::sym("tidyr::gather(key = key, value = value, new_sp_m014:newrel_f65, na.rm = TRUE)") # nolint solution <- rlang::sym("tidyr::gather(key = key, value = value, new_sp_m014:newrel_f65, na.rm = TRUE)") # nolint expect_correct( - check_code(grader_args = list(user_quo = user, solution_quo = solution)) + grade_code(grader_args = list(user_quo = user, solution_quo = solution)) ) }) diff --git a/tests/testthat/test_check_result.R b/tests/testthat/test_check_result.R index d2474f5f..f4c09420 100644 --- a/tests/testthat/test_check_result.R +++ b/tests/testthat/test_check_result.R @@ -2,14 +2,14 @@ context("Check Result Condi") test_that("Provide a passing solution. Give the students a fighting chance!", { testthat::expect_error( - check_result( + grade_result( grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) ) ) testthat::expect_error( - check_result( + grade_result( fail_if(~ .result == 5, "You were supposed to do this other thing!"), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) @@ -17,7 +17,7 @@ test_that("Provide a passing solution. Give the students a fighting chance!", { ) testthat::expect_error( - check_result( + grade_result( fail_if(~ .result == 5, "You were supposed to do this other thing!"), fail_if(~ .result == 10, "You were supposed to do this other thing!"), grader_args = list(), @@ -29,7 +29,7 @@ test_that("Provide a passing solution. Give the students a fighting chance!", { test_that("Spots differences in atomics -- formula", { expect_correct( - check_result( + grade_result( pass_if(~ .result == 5, "This is a correct message"), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) @@ -37,7 +37,7 @@ test_that("Spots differences in atomics -- formula", { ) expect_wrong( - check_result( + grade_result( pass_if(~ .result == 5, "This is a wrong answer!"), grader_args = list(), learnr_args = list(last_value = 100000, envir_prep = new.env()) @@ -45,7 +45,7 @@ test_that("Spots differences in atomics -- formula", { ) expect_wrong( - check_result( + grade_result( fail_if(~ .result == 5, "You were supposed to do this other thing!"), pass_if(~ TRUE, "should never reach here"), grader_args = list(), @@ -57,21 +57,21 @@ test_that("Spots differences in atomics -- formula", { test_that("Spots differences in atomics -- function", { expect_correct( - check_result( + grade_result( pass_if(function(x) x == 5, "This is a correct message"), learnr_args = list(last_value = 5) ) ) expect_wrong( - check_result( + grade_result( pass_if(function(x) x == 5, "This is a wrong answer!"), learnr_args = list(last_value = 100000) ) ) expect_wrong( - check_result( + grade_result( fail_if(function(x) x == 5, "You were supposed to do this other thing!"), pass_if(~ TRUE, "should never reach here"), learnr_args = list(last_value = 5) @@ -82,21 +82,21 @@ test_that("Spots differences in atomics -- function", { test_that("Spots differences in atomics -- value", { expect_correct( - check_result( + grade_result( pass_if(5, "This is a correct message"), learnr_args = list(last_value = 5) ) ) expect_wrong( - check_result( + grade_result( pass_if(5, "This is a wrong answer!"), learnr_args = list(last_value = 100000) ) ) expect_wrong( - check_result( + grade_result( fail_if(5, "You were supposed to do this other thing!"), pass_if(~ TRUE, "should never reach here"), learnr_args = list(last_value = 5) diff --git a/tests/testthat/test_check_result_df.R b/tests/testthat/test_check_result_df.R index 4ea7400b..f2e0ffb6 100644 --- a/tests/testthat/test_check_result_df.R +++ b/tests/testthat/test_check_result_df.R @@ -7,7 +7,7 @@ test_that("Comparing dataframes, testing for null env", { testthat::expect_equal(billboard_user, billboard_solution) expect_correct( - check_result( + grade_result( pass_if(~ identical(.result, billboard_solution), "This is a correct message"), learnr_args = list(last_value = billboard_user, envir_prep = new.env()) ) diff --git a/tests/testthat/test_check_result_message.R b/tests/testthat/test_check_result_message.R index 928e851b..94a5afbf 100644 --- a/tests/testthat/test_check_result_message.R +++ b/tests/testthat/test_check_result_message.R @@ -1,4 +1,4 @@ -context("Check check_result messages") +context("Check grade_conditions messages") expect_message <- function(x, message, correct) { expect_s3_class(x, "grader_graded") @@ -10,7 +10,7 @@ test_that("Correct messages without random praise", { glue_correct_no_praise <- "{ .message } { .correct }" expect_message( - check_result( + grade_result( pass_if(~ .result == 5, message = "A pass_if message."), correct = "A correct message.", grader_args = list(), @@ -22,7 +22,7 @@ test_that("Correct messages without random praise", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 5), correct = "Only a correct message.", grader_args = list(), @@ -34,7 +34,7 @@ test_that("Correct messages without random praise", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 5, "Only a pass_if message."), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()), @@ -45,7 +45,7 @@ test_that("Correct messages without random praise", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 5), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()), @@ -60,7 +60,7 @@ test_that("Incorrect messages no match pass_if", { glue_incorrect_no_praise <- "{ .message } { .incorrect }" expect_message( - check_result( + grade_result( pass_if(~ .result == 42), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()), @@ -71,7 +71,7 @@ test_that("Incorrect messages no match pass_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42, message = "This does nothing (expected)."), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()) @@ -81,7 +81,7 @@ test_that("Incorrect messages no match pass_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42, message = "This does nothing (expected)."), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()), @@ -92,7 +92,7 @@ test_that("Incorrect messages no match pass_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42), grader_args = list(), learnr_args = list(last_value = 5, envir_prep = new.env()), @@ -105,7 +105,7 @@ test_that("Incorrect messages no match pass_if", { test_that("Incorrect messages match fail_if", { expect_message( - check_result( + grade_result( pass_if(~ .result == 42), fail_if(~ .result == 5), grader_args = list(), @@ -116,7 +116,7 @@ test_that("Incorrect messages match fail_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42, message = "No match here."), fail_if(~ .result == 5, message = "Found an incorrect match."), grader_args = list(), @@ -127,7 +127,7 @@ test_that("Incorrect messages match fail_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42, message = "No match here."), fail_if(~ .result == 5, message = "Found an incorrect match."), grader_args = list(), @@ -139,7 +139,7 @@ test_that("Incorrect messages match fail_if", { ) expect_message( - check_result( + grade_result( pass_if(~ .result == 42), fail_if(~ .result == 5), grader_args = list(), diff --git a/tests/testthat/test_grade_learnr.R b/tests/testthat/test_grade_learnr.R index 2a654659..2f3b74fc 100644 --- a/tests/testthat/test_grade_learnr.R +++ b/tests/testthat/test_grade_learnr.R @@ -44,11 +44,11 @@ test_grade_learnr <- function(user_code, last_value = last_value) } -test_that("Grade learnr check_result", { +test_that("Grade learnr grade_result", { expect_correct( test_grade_learnr( user_code = "4", - check_code = "check_result( + check_code = "grade_result( pass_if(~ .result == 4, 'yes. you did it.'), correct = 'this other correct message.', glue_correct = '{ .message } { .correct }' @@ -62,7 +62,7 @@ test_that("Grade learnr check_code", { expect_correct( test_grade_learnr( user_code = "4", - check_code = "check_code(correct = 'This works', glue_correct = '{.correct}')", + check_code = "grade_code(correct = 'This works', glue_correct = '{.correct}')", solution_code = "4" ), "This works" @@ -71,7 +71,7 @@ test_that("Grade learnr check_code", { expect_wrong( test_grade_learnr( user_code = "exp(log(2))", - check_code = "check_code(glue_incorrect = '{.message}')", + check_code = "grade_code(glue_incorrect = '{.message}')", solution_code = "exp(log(1))" ), "I expected 1 where you wrote 2." diff --git a/tests/testthat/test_test_result.R b/tests/testthat/test_test_result.R deleted file mode 100644 index b928fa9c..00000000 --- a/tests/testthat/test_test_result.R +++ /dev/null @@ -1,39 +0,0 @@ -context("Test Result") - -expect_message <- function(x, message, correct = FALSE) { - expect_s3_class(x, "grader_graded") - expect_equal(x$correct, correct) - expect_true(grepl(message, paste0(x$message, collapse = ""), fixed = TRUE)) -} - -test_that("Test formula type", { - example_function <- function(x){ - return(x + 1) - } - - expect_correct( - test_result( - pass_if(~ .result(3) == 4), - pass_if(~ .result(10) == 11), - grader_args = list(), - learnr_args = list(last_value = example_function, envir_prep = new.env()) - ) - ) - - expect_wrong( - test_result( - pass_if(~ .result(3) == 4), - fail_if(~ .result(10) == 11), - grader_args = list(), - learnr_args = list(last_value = example_function, envir_prep = new.env()) - ) - ) - - expect_wrong( - test_result( - pass_if(~ .result(100) == 1), - grader_args = list(), - learnr_args = list(last_value = example_function, envir_prep = new.env()) - ) - ) -}) diff --git a/tests/testthat/test_test_result_message.R b/tests/testthat/test_test_result_message.R index ffe57fa6..e924031f 100644 --- a/tests/testthat/test_test_result_message.R +++ b/tests/testthat/test_test_result_message.R @@ -1,4 +1,4 @@ -context("Check test_result messages") +context("Check grade_conditions messages") expect_message <- function(x, message, correct) { expect_s3_class(x, "grader_graded") @@ -13,7 +13,7 @@ test_that("Correct messages without random praise", { } expect_message( - test_result( + grade_conditions( pass_if(~ .result(3) == 4), pass_if(~ .result(10) == 11), grader_args = list(), @@ -32,7 +32,7 @@ test_that("Incorrect mesages without random praise", { } expect_message( - test_result( + grade_conditions( pass_if(~ .result(3) == 4), fail_if(~ .result(10) == 11), grader_args = list(),