datacamp / testwhat

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

Document how index arg works for nested functions #214

Open richierocks opened 6 years ago

richierocks commented 6 years ago

Consider this ggplot

library(ggplot2)
ggplot(Orange, aes(age, circumference)) +
  geom_point() +
  geom_line(aes(color = Tree))

This has 2 calls to aes(), so on first glance, it seems I want to check this with

ex() %>% check_function("ggplot") %>% {
  check_arg(., "data") %>% check_equal()
  check_arg(., "mapping") %>% check_function("aes") %>% {
    check_arg(., "x") %>% check_equal(eval = FALSE)
    check_arg(., "y") %>% check_equal(eval = FALSE)
  }
}
ex() %>% check_function("geom_point") %>% {
  check_arg(., "mapping") %>% check_function("aes", index = 2) %>% {
    check_arg(., "color") %>% check_equal(eval = FALSE)
  }
}

But the each call to aes() is nested inside another check_function(), and I think this is restricting the scope. So I think the SCTs I really need are

ex() %>% check_function("ggplot") %>% {
  check_arg(., "data") %>% check_equal()
  check_arg(., "mapping") %>% check_function("aes") %>% {
    check_arg(., "x") %>% check_equal(eval = FALSE)
    check_arg(., "y") %>% check_equal(eval = FALSE)
  }
}
ex() %>% check_function("geom_point") %>% {
  check_arg(., "mapping") %>% check_function("aes") %>% {  # <- this line different
    check_arg(., "color") %>% check_equal(eval = FALSE)
  }
}

It's worth having an example of how the index is calculated: on the whole code or on a subset of the code provided by the state.

hermansje commented 6 years ago

The first SCT was the way it worked before we fixed #206. The second SCT is how it was intended and how it should work, after deploying that fix.

I will add an example.