/inst/tests/test-aes.r

http://github.com/hadley/ggplot2 · R · 62 lines · 50 code · 12 blank · 0 comment · 0 complexity · 38c1a42c898de0abf1f995e748276833 MD5 · raw file

  1. context("Creating aesthetic mappings")
  2. test_that("function aes", {
  3. expect_equal(aes(x = mpg, y = wt),
  4. structure(list(x = bquote(mpg), y = bquote(wt)), class = "uneval"))
  5. expect_equal(aes(x = mpg ^ 2, y = wt / cyl),
  6. structure(list(x = bquote(mpg ^ 2), y = bquote(wt / cyl)), class = "uneval"))
  7. })
  8. test_that("function aes_string", {
  9. expect_equal(aes_string(x = "mpg", y = "wt"),
  10. structure(list(x = bquote(mpg), y = bquote(wt)), class = "uneval"))
  11. expect_equal(aes_string(x = "mpg ^ 2", y = "wt / cyl"),
  12. structure(list(x = bquote(mpg ^ 2), y = bquote(wt / cyl)), class = "uneval"))
  13. })
  14. test_that("function aes_all", {
  15. expect_equal(aes_all(names(mtcars)),
  16. structure(
  17. list(
  18. mpg = bquote(mpg),
  19. cyl = bquote(cyl),
  20. disp = bquote(disp),
  21. hp = bquote(hp),
  22. drat = bquote(drat),
  23. wt = bquote(wt),
  24. qsec = bquote(qsec),
  25. vs = bquote(vs),
  26. am = bquote(am),
  27. gear = bquote(gear),
  28. carb = bquote(carb)),
  29. class = "uneval"))
  30. expect_equal(aes_all(c("x", "y", "col", "pch")),
  31. structure(list(x = bquote(x), y = bquote(y), colour = bquote(col), shape = bquote(pch)), class = "uneval"))
  32. })
  33. test_that("function aes_auto", {
  34. df <- data.frame(x = 1, y = 1, colour = 1, label = 1, pch = 1)
  35. expect_equal(aes_auto(df),
  36. structure(list(colour = bquote(colour), label = bquote(label), shape = bquote(pch), x = bquote(x), y = bquote(y)), class = "uneval"))
  37. expect_equal(aes_auto(names(df)),
  38. structure(list(colour = bquote(colour), label = bquote(label), shape = bquote(pch), x = bquote(x), y = bquote(y)), class = "uneval"))
  39. df <- data.frame(xp = 1:3, y = 1:3, colour = 1:3, txt = letters[1:3], foo = 1:3)
  40. expect_equal(aes_auto(df, x = xp, label = txt),
  41. structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))
  42. expect_equal(aes_auto(names(df), x = xp, label = txt),
  43. structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))
  44. expect_equal(aes_auto(x = xp, label = txt, data = df),
  45. structure(list(colour = bquote(colour), y = bquote(y), x = bquote(xp), label = bquote(txt)), class = "uneval"))
  46. df <- data.frame(foo = 1:3)
  47. expect_equal(aes_auto(df, x = xp, y = yp),
  48. structure(list(x = bquote(xp), y = bquote(yp)), class = "uneval"))
  49. expect_equal(aes_auto(df), structure(setNames(list(), character(0)), class = "uneval"))
  50. })