Skip to content

Commit acbaec7

Browse files
pkqhadley
authored andcommitted
Copyedit testthat tests (#2634)
Consistently use lower case to name tests Make test names grammatically correct Apply consistent whitespace rules
1 parent 1f7a4eb commit acbaec7

35 files changed

+68
-139
lines changed

tests/testthat/test-add.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
context("Adding plot elements")
22

3-
test_that("Mapping class is preserved when adding uneval objects", {
3+
test_that("mapping class is preserved when adding uneval objects", {
44
p <- ggplot(mtcars) + aes(wt, mpg)
55
expect_identical(class(p$mapping), "uneval")
66
})

tests/testthat/test-aes-grouping.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ df <- data.frame(
99
group <- function(x) as.vector(layer_data(x, 1)$group)
1010
groups <- function(x) length(unique(group(x)))
1111

12+
1213
test_that("one group per combination of discrete vars", {
1314
plot <- ggplot(df, aes(x, x)) + geom_point()
1415
expect_equal(group(plot), rep(NO_GROUP, 4))

tests/testthat/test-aes-setting.r

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
context("Aes - setting values")
22

3-
test_that("Aesthetic parameters must match length of data", {
3+
test_that("aesthetic parameters match length of data", {
44
df <- data.frame(x = 1:5, y = 1:5)
55
p <- ggplot(df, aes(x, y))
66

@@ -13,7 +13,6 @@ test_that("Aesthetic parameters must match length of data", {
1313
expect_error(set_colours(rep("red", 3)), "must be either length 1")
1414
expect_error(set_colours(rep("red", 4)), "must be either length 1")
1515
set_colours(rep("red", 5))
16-
1716
})
1817

1918
test_that("legend filters out aesthetics not of length 1", {
@@ -24,7 +23,6 @@ test_that("legend filters out aesthetics not of length 1", {
2423
# Ideally would test something in the legend data structure, but
2524
# that's not easily accessible currently.
2625
expect_error(ggplot_gtable(ggplot_build(p)), NA)
27-
2826
})
2927

3028
test_that("alpha affects only fill colour of solid geoms", {

tests/testthat/test-aes.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test_that("aes_string() doesn't parse non-strings", {
2323
expect_identical(aes_string(0.4)$x, 0.4)
2424
})
2525

26-
test_that("aes_q() & aes_string() preserves explicit NULLs", {
26+
test_that("aes_q() & aes_string() preserve explicit NULLs", {
2727
expect_equal(aes_q(NULL), aes(NULL))
2828
expect_equal(aes_q(x = NULL), aes(NULL))
2929
expect_equal(aes_q(colour = NULL), aes(colour = NULL))

tests/testthat/test-build.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_that("there is one data frame for each layer", {
1515
expect_equal(nlayers(l3), 3)
1616
})
1717

18-
test_that("position aesthetics coerced to correct type", {
18+
test_that("position aesthetics are coerced to correct type", {
1919
l1 <- ggplot(df, aes(x, y)) + geom_point()
2020
d1 <- layer_data(l1, 1)
2121

tests/testthat/test-coord-polar.r

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
context("coord_polar")
22

3-
test_that("Polar distance calculation", {
3+
test_that("polar distance is calculated correctly", {
44
dat <- data.frame(
55
theta = c(0, 2*pi, 2, 6, 6, 1, 1, 0),
66
r = c(0, 0, 0.5, 0.5, 1, 1, 0.75, .5))
@@ -26,9 +26,7 @@ test_that("Polar distance calculation", {
2626
# geom_point(alpha=0.3) + coord_polar()
2727
})
2828

29-
30-
31-
test_that("Polar distance calculation ignores NA's", {
29+
test_that("polar distance calculation ignores NA's", {
3230

3331
# These are r and theta values; we'll swap them around for testing
3432
x1 <- c(0, 0.5, 0.5, NA, 1)
@@ -39,7 +37,6 @@ test_that("Polar distance calculation ignores NA's", {
3937
dists <- dist_polar(x2, x1)
4038
expect_equal(is.na(dists), c(FALSE, FALSE, TRUE, TRUE))
4139

42-
4340
# NA on the end
4441
x1 <- c(0, 0.5, 0.5, 1, NA)
4542
x2 <- c(0, 1, 2, 0, 1)
@@ -48,7 +45,6 @@ test_that("Polar distance calculation ignores NA's", {
4845
dists <- dist_polar(x2, x1)
4946
expect_equal(is.na(dists), c(FALSE, FALSE, FALSE, TRUE))
5047

51-
5248
# NAs in each vector - also have NaN
5349
x1 <- c(0, 0.5, 0.5, 1, NA)
5450
x2 <- c(NaN, 1, 2, NA, 1)
@@ -58,7 +54,6 @@ test_that("Polar distance calculation ignores NA's", {
5854
expect_equal(is.na(dists), c(TRUE, FALSE, TRUE, TRUE))
5955
})
6056

61-
6257
test_that("clipping can be turned off and on", {
6358
# clip can be turned on and off
6459
p <- ggplot() + coord_polar()
@@ -73,7 +68,7 @@ test_that("clipping can be turned off and on", {
7368

7469
# Visual tests ------------------------------------------------------------
7570

76-
test_that("Polar coordinates draws correctly", {
71+
test_that("polar coordinates draw correctly", {
7772
theme <- theme_test() +
7873
theme(
7974
axis.text.y = element_blank(),

tests/testthat/test-empty-data.r

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ test_that("layers with empty data are silently omitted", {
2020
expect_equal(nrow(layer_data(d, 1)), 0)
2121
})
2222

23-
2423
test_that("plots with empty data and vectors for aesthetics work", {
2524
d <- ggplot(NULL, aes(1:5, 1:5)) + geom_point()
2625
expect_equal(nrow(layer_data(d)), 5)
@@ -32,7 +31,6 @@ test_that("plots with empty data and vectors for aesthetics work", {
3231
expect_equal(nrow(layer_data(d)), 5)
3332
})
3433

35-
3634
test_that("layers with empty data are silently omitted with facet_wrap", {
3735
# Empty data, facet_wrap, throws error
3836
d <- ggplot(df0, aes(mpg, wt)) +
@@ -56,7 +54,6 @@ test_that("layers with empty data are silently omitted with facet_grid", {
5654
expect_equal(nrow(layer_data(d, 2)), nrow(mtcars))
5755
})
5856

59-
6057
test_that("empty data overrides plot defaults", {
6158
# Should error when totally empty data frame because there's no x and y
6259
d <- ggplot(mtcars, aes(mpg, wt)) +

tests/testthat/test-facet-.r

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test_that("facets split up the data", {
6464
expect_equal(d1$PANEL, factor(1:3))
6565
})
6666

67-
test_that("facet_wrap() accept vars()", {
67+
test_that("facet_wrap() accepts vars()", {
6868
p <- ggplot(df, aes(x, y)) + geom_point()
6969
p2 <- p + facet_wrap(vars(z))
7070

@@ -130,7 +130,6 @@ test_that("facets with free scales scale independently", {
130130
expect_true(sd(d3$y) < 1e-10)
131131
})
132132

133-
134133
test_that("shrink parameter affects scaling", {
135134
l1 <- ggplot(df, aes(1, y)) + geom_point()
136135
r1 <- pranges(l1)
@@ -148,8 +147,7 @@ test_that("shrink parameter affects scaling", {
148147
expect_equal(r3$y[[1]], c(1, 3))
149148
})
150149

151-
152-
test_that("Facet variables", {
150+
test_that("facet variables", {
153151
expect_identical(facet_null()$vars(), character(0))
154152
expect_identical(facet_wrap(~ a)$vars(), "a")
155153
expect_identical(facet_grid(a ~ b)$vars(), c("a", "b"))
@@ -163,9 +161,10 @@ test_that("facet gives clear error if ", {
163161
)
164162
})
165163

164+
166165
# Visual tests ------------------------------------------------------------
167166

168-
test_that("Facet labels can respect both justification and margin arguments", {
167+
test_that("facet labels respect both justification and margin arguments", {
169168

170169
df <- data.frame(
171170
x = 1:2,

tests/testthat/test-facet-layout.r

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ panel_layout <- function(facet, data) {
1111
layout$layout
1212
}
1313

14-
test_that("grid: single row and single col equivalent", {
14+
test_that("grid: single row and single col are equivalent", {
1515
row <- panel_layout(facet_grid(a~.), list(a))
1616
col <- panel_layout(facet_grid(.~a), list(a))
1717

@@ -34,7 +34,7 @@ test_that("grid: includes all combinations", {
3434
expect_equal(nrow(all), 4)
3535
})
3636

37-
test_that("wrap and grid equivalent for 1d data", {
37+
test_that("wrap and grid are equivalent for 1d data", {
3838
rowg <- panel_layout(facet_grid(a~.), list(a))
3939
roww <- panel_layout(facet_wrap(~a, ncol = 1), list(a))
4040
expect_equal(roww, rowg)
@@ -105,7 +105,6 @@ test_that("wrap: drop = FALSE preserves unused levels", {
105105
wrap_b <- panel_layout(facet_wrap(~b, drop = FALSE), list(a2))
106106
expect_equal(nrow(wrap_b), 4)
107107
expect_equal(as.character(wrap_b$b), as.character(4:1))
108-
109108
})
110109

111110
test_that("grid: drop = FALSE preserves unused levels", {
@@ -121,7 +120,6 @@ test_that("grid: drop = FALSE preserves unused levels", {
121120
expect_equal(nrow(grid_ab), 16)
122121
expect_equal(as.character(grid_ab$a), as.character(rep(1:4, each = 4)))
123122
expect_equal(as.character(grid_ab$b), as.character(rep(4:1, 4)))
124-
125123
})
126124

127125
# Missing behaviour ----------------------------------------------------------

tests/testthat/test-facet-map.r

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ panel_map_one <- function(facet, data, plot_data = data) {
1010
layout$setup(list(data), plot_data)[[1]]
1111
}
1212

13-
14-
test_that("two col cases with no missings adds single extra column", {
13+
test_that("two col cases with no missings adds a single extra column", {
1514
loc <- panel_map_one(facet_grid(cyl~vs), mtcars)
1615

1716
expect_equal(nrow(loc), nrow(mtcars))
1817
expect_equal(ncol(loc), ncol(mtcars) + 1)
1918

2019
match <- unique(loc[c("cyl", "vs", "PANEL")])
2120
expect_equal(nrow(match), 5)
22-
2321
})
2422

2523
test_that("margins add extra data", {
@@ -28,7 +26,6 @@ test_that("margins add extra data", {
2826
expect_equal(nrow(loc), nrow(df) * 2)
2927
})
3028

31-
3229
test_that("grid: missing facet columns are duplicated", {
3330
facet <- facet_grid(a~b)
3431

@@ -60,7 +57,6 @@ test_that("wrap: missing facet columns are duplicated", {
6057
loc_c <- panel_map_one(facet, df_c, plot_data = df)
6158
expect_equal(nrow(loc_c), 4)
6259
expect_equal(loc_c$PANEL, factor(1:4))
63-
6460
})
6561

6662
# Missing behaviour ----------------------------------------------------------
@@ -71,7 +67,7 @@ a3 <- data.frame(
7167
c = factor(c(1:3, NA), exclude = NULL)
7268
)
7369

74-
test_that("wrap: missing values located correctly", {
70+
test_that("wrap: missing values are located correctly", {
7571
facet <- facet_wrap(~b, ncol = 1)
7672
loc_b <- panel_map_one(facet, data.frame(b = NA), plot_data = a3)
7773
expect_equal(as.character(loc_b$PANEL), "4")
@@ -81,7 +77,7 @@ test_that("wrap: missing values located correctly", {
8177
expect_equal(as.character(loc_c$PANEL), "4")
8278
})
8379

84-
test_that("grid: missing values located correctly", {
80+
test_that("grid: missing values are located correctly", {
8581
facet <- facet_grid(b~.)
8682
loc_b <- panel_map_one(facet, data.frame(b = NA), plot_data = a3)
8783
expect_equal(as.character(loc_b$PANEL), "4")
@@ -160,5 +156,4 @@ test_that("wrap: facet order follows default data frame order", {
160156
lay <- get_layout(ggplot(mapping = aes(x, y)) + facet_wrap(~fx) +
161157
geom_point(data = d) + geom_blank(data = d2))
162158
expect_equal(as.character(lay$fx), c("c","b","a")[lay$PANEL])
163-
164159
})

0 commit comments

Comments
 (0)