PageRenderTime 37ms CodeModel.GetById 31ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

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