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
})

tests/testthat/test-fortify.r

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

3-
test_that("Spatial polygons have correct ordering", {
3+
test_that("spatial polygons have correct ordering", {
44
skip_if_not_installed("sp")
55

66
make_square <- function(x = 0, y = 0, height = 1, width = 1){
@@ -24,7 +24,6 @@ test_that("Spatial polygons have correct ordering", {
2424
sp::Polygons(list(make_square(0,1)), 4),
2525
sp::Polygons(list(make_square(0,3)), 5))
2626

27-
2827
polys_sp <- sp::SpatialPolygons(polys)
2928
fake_sp <- sp::SpatialPolygonsDataFrame(polys_sp, fake_data)
3029

@@ -34,7 +33,6 @@ test_that("Spatial polygons have correct ordering", {
3433
fake_sp2 <- sp::SpatialPolygonsDataFrame(polys2_sp, fake_data)
3534

3635
expect_equivalent(fortify(fake_sp), plyr::arrange(fortify(fake_sp2), id, order))
37-
3836
})
3937

4038
test_that("fortify.default proves a helpful error with class uneval", {

tests/testthat/test-function-args.r

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ test_that("geom_xxx and GeomXxx$draw arg defaults match", {
4242
})
4343
})
4444

45-
4645
test_that("stat_xxx and StatXxx$compute_panel arg defaults match", {
4746
ggplot2_ns <- asNamespace("ggplot2")
4847
objs <- ls(ggplot2_ns)

tests/testthat/test-geom-dotplot.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ context("geom_dotplot")
33
set.seed(111)
44
dat <- data.frame(x = LETTERS[1:2], y = rnorm(30), g = LETTERS[3:5])
55

6-
test_that("Dodging works", {
6+
test_that("dodging works", {
77
p <- ggplot(dat, aes(x = x, y = y, fill = g)) +
88
geom_dotplot(
99
binwidth = 0.2,
@@ -34,8 +34,7 @@ test_that("Dodging works", {
3434
expect_true(all(abs(df$x - df$xmin - dwidth/2) < 1e-6))
3535
})
3636

37-
38-
test_that("Binning works", {
37+
test_that("binning works", {
3938
bp <- ggplot(dat, aes(y)) +
4039
geom_dotplot(binwidth = .4, method = "histodot")
4140
x <- layer_data(bp)$x
@@ -53,7 +52,6 @@ test_that("Binning works", {
5352
expect_false(all(abs((x - min(x) + 1e-7) %% .4) < 1e-6))
5453
})
5554

56-
5755
test_that("NA's result in warning from stat_bindot", {
5856
set.seed(122)
5957
dat <- data.frame(x = rnorm(20))
@@ -64,7 +62,7 @@ test_that("NA's result in warning from stat_bindot", {
6462
"Removed 2 rows.*stat_bindot")
6563
})
6664

67-
test_that("When binning on y-axis, limits depend on the panel", {
65+
test_that("when binning on y-axis, limits depend on the panel", {
6866
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
6967
geom_dotplot(binaxis='y')
7068

@@ -78,6 +76,7 @@ test_that("When binning on y-axis, limits depend on the panel", {
7876
expect_false(all(equal_limits2))
7977
})
8078

79+
8180
# Visual tests ------------------------------------------------------------
8281

8382
test_that("geom_dotplot draws correctly", {

tests/testthat/test-geom-hex.R

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

3-
test_that("density and value summaries available", {
3+
test_that("density and value summaries are available", {
44
df <- data.frame(x = c(1, 1, 1, 2), y = c(1, 1, 1, 2))
55
base <- ggplot(df, aes(x, y)) +
66
geom_hex()

tests/testthat/test-geom-path.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test_that("keep_mid_true drops leading/trailing FALSE", {
77
expect_equal(keep_mid_true(c(F, T, F, T, T)), c(F, T, T, T, T))
88
})
99

10+
1011
# Visual tests ------------------------------------------------------------
1112

1213
test_that("geom_path draws correctly", {

tests/testthat/test-geom-sf.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
context("geom-sf")
22

3+
34
# Visual tests ------------------------------------------------------------
45

56
test_that("geom_sf draws correctly", {

tests/testthat/test-geom-smooth.R

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

3-
test_that("Data is ordered by x", {
3+
test_that("data is ordered by x", {
44
df <- data.frame(x = c(1, 5, 2, 3, 4), y = 1:5)
55

66
ps <- ggplot(df, aes(x, y))+
@@ -9,7 +9,7 @@ test_that("Data is ordered by x", {
99
expect_equal(layer_data(ps)[c("x", "y")], df[order(df$x), ])
1010
})
1111

12-
test_that("Default smoothing methods for small and large data sets work", {
12+
test_that("default smoothing methods for small and large data sets work", {
1313
# test small data set
1414
set.seed(6531)
1515
x <- rnorm(10)
@@ -48,9 +48,9 @@ test_that("Default smoothing methods for small and large data sets work", {
4848
"method = 'gam' and formula 'y ~ s\\(x, bs = \"cs\"\\)"
4949
)
5050
expect_equal(plot_data$y, as.numeric(out))
51-
5251
})
5352

53+
5454
# Visual tests ------------------------------------------------------------
5555

5656
test_that("geom_smooth() works with alternative stats", {

0 commit comments

Comments
 (0)