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

Feedback is highlighting the wrong part of the code #157

Closed benjamin-feder closed 6 years ago

benjamin-feder commented 6 years ago

Here's the details of the question:

@pre_exercise_code

download.file("https://assets.datacamp.com/production/repositories/1613/datasets/bbe39331b108bf00e3ad1d213e0d8fd8b7cc88ee/bakeoff.csv", 
              destfile = "bakeoff.csv", quiet = TRUE)
library <- function(...) {
  suppressPackageStartupMessages(base::library(...))
}
library(readr)
library(dplyr)
bakeoff <- read_csv("bakeoff.csv", 
                    na = c("", "NA", "UNKNOWN", "N/A"),
                    col_types = cols(
                      result = col_factor(levels = NULL)
                    ))  

@sample_code

# Count the number of rows by series and baker
bakers_by_series <- bakeoff %>% 
  count(series, baker)

# Count again by series
bakers_by_series

@solution

# Count the number of rows by series and baker
bakers_by_series <- bakeoff %>% 
  count(series, baker)

# Count again by series
bakers_by_series %>% 
  count(series)

@sct

ex() %>% check_object("bakers_by_series") %>% check_function("count", index = 1) %>% check_result() %>% check_equal()
ex() %>% check_function("count", index = 2) %>% check_result() %>% check_equal()
ex() %>% check_error()

Let's say instead of counting by series, we decided to count by baker by accident in the second part of the solution code. For some reason, the sct marks this as incorrect, but highlights the first part of the code with the assignment, even though it's the second chunk that is wrong.

filipsch commented 6 years ago

@benjamin-feder I tried to reproduce. Your SCT is wrong. Do not pipe the state check_object() produces into check_function()!

The following should work:

ex() %>% check_function("count", index = 1) %>% check_result() %>% check_equal()
ex() %>% check_function("count", index = 2) %>% check_result() %>% check_equal()
ex() %>% check_error()

This would be a better SCT even:

test_correct(
  ex() %>% check_object("bakers_by_series") %>% check_equal(),
  ex() %>% check_function("count", index = 1) %>% check_result() %>% check_equal()
)
ex() %>% check_function("count", index = 2) %>% check_result() %>% check_equal()

Let me know if something is not clear. Please verify that the highlighting is correct now, and let me know when it isn't!