Skip to content

Commit

Permalink
Only use gradethis_equal.list() method if both objects are bare lis…
Browse files Browse the repository at this point in the history
…ts (#357)
  • Loading branch information
rossellhayes authored Jun 2, 2023
1 parent a2ebe90 commit 7da5743
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* `grade_code()` no longer fails if `.envir_result` or `.envir_solution` is missing (#355).
* `detect_mistakes()` now keeps a version of standardized user and solution code with and without default arguments added. Missing arguments are detected by comparing the user code with defaults to the solution code without defaults. Surplus arguments are detected by comparing the user code without defaults to the solution code with defaults (#356).
* This helps avoid spurious feedback when comparing code that involves S3 methods. If the user's code differs from the solution code in a way that means a different S3 method is used, the standardized code may gain different default arguments. This could result in feedback about missing or surplus arguments that were added by code standardization rather than by the student, which is not actionable feedback. By no longer looking for default arguments that are missing or surplus in the user code, we ensure that students receive more actionable feedback, likely about the incorrect argument that resulted in the use of a different S3 method.
* The `gradethis_equal.list()` method is now only used if both `x` and `y` are bare lists (as defined by `rlang::is_bare_list()`) (#357).
* This fixes a bug where a list could be marked as equal to another object with the same contents but a different class, e.g. `list(a = 1, b = 2)` and `c(a = 1, b = 2)` or `data.frame(a = 1, b = 2)`.

# gradethis 0.2.13

Expand Down
2 changes: 1 addition & 1 deletion R/gradethis_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ gradethis_equal.list <- function(
# Only use this method for objects of class `list`,
# not just anything that inherits list (like data frames)
if (!rlang::is_bare_list(x) || !rlang::is_bare_list(y)) {
NextMethod()
return(NextMethod())
}

# First check with `identical()`, since it's fast
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-gradethis_equal.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ test_that("gradethis_equal.list() checks names", {
expect_false(gradethis_equal(list(pi, letters), list(a = pi, b = letters)))
})

test_that("gradethis_equal.list() is only used when x and y are both bare lists", {
example_list <- list(1, 2, 3)
example_vector <- c(1, 2, 3)

expect_false(gradethis_equal(example_list, example_vector))
expect_false(gradethis_equal(example_vector, example_list))
expect_false(gradethis_equal(list(example_list), list(example_vector)))
expect_false(gradethis_equal(list(example_vector), list(example_list)))

example_list <- list(a = 1, b = 2)
example_data_frame <- data.frame(a = 1, b = 2)

expect_false(gradethis_equal(example_list, example_data_frame))
expect_false(gradethis_equal(example_data_frame, example_list))
expect_false(gradethis_equal(list(example_list), list(example_data_frame)))
expect_false(gradethis_equal(list(example_data_frame), list(example_list)))
})

test_that("gradethis_equal uses methods from ggcheck", {
skip_if_not_installed("ggcheck", "0.0.5")
skip_if_not_installed("ggplot2")
Expand Down

0 comments on commit 7da5743

Please sign in to comment.