Skip to content

Commit 80b1312

Browse files
committed
more polygon tests
1 parent e977416 commit 80b1312

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/testthat/test-ggplot-polygons.R

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test_that("polygons filled with the same color become one trace", {
3030
12, 13, 13, 12, 12, NA,
3131
10, 10)
3232
expect_equal(tr$x, expected.x)
33+
expect_equal(tr$fill, "tozerox")
3334
expected.y <-
3435
c(0, 0, 1, 1, 0, NA,
3536
0, 0, 1, 1, 0, NA,
@@ -49,6 +50,7 @@ test_that("polygons with different color become separate traces", {
4950
traces.by.name <- list()
5051
for(tr in info$traces){
5152
expect_equal(tr$fillcolor, toRGB("grey"))
53+
expect_equal(tr$fill, "tozerox")
5254
traces.by.name[[tr$name]] <- tr
5355
}
5456
expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10))
@@ -85,6 +87,7 @@ test_that("geom_polygon(aes(fill), color) -> line$color", {
8587
traces.by.name <- list()
8688
for(tr in info$traces){
8789
expect_equal(tr$line$color, toRGB("black"))
90+
expect_equal(tr$fill, "tozerox")
8891
traces.by.name[[tr$name]] <- tr
8992
}
9093
expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10))
@@ -104,6 +107,7 @@ test_that("geom_polygon(aes(linetype), fill, color)", {
104107
for(tr in info$traces){
105108
expect_equal(tr$fillcolor, toRGB("red"))
106109
expect_equal(tr$line$color, toRGB("blue"))
110+
expect_equal(tr$fill, "tozerox")
107111
traces.by.name[[tr$name]] <- tr
108112
}
109113
expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10))
@@ -123,6 +127,7 @@ test_that("geom_polygon(aes(size), fill, colour)", {
123127
for(tr in info$traces){
124128
expect_equal(tr$fillcolor, toRGB("orange"))
125129
expect_equal(tr$line$color, toRGB("black"))
130+
expect_equal(tr$fill, "tozerox")
126131
traces.by.name[[tr$name]] <- tr
127132
}
128133
expect_equal(traces.by.name$left$x, c(10, 11, 11, 10, 10))
@@ -145,3 +150,60 @@ test_that("borders become one trace with NA", {
145150

146151
save_outputs(gg, "polygons-canada-borders")
147152
})
153+
154+
x <- c(0, -1, 2, -2, 1)
155+
y <- c(2, 0, 1, 1, 0)
156+
stars <-
157+
rbind(data.frame(x, y, group="left"),
158+
data.frame(x=x+10, y, group="right"))
159+
star.group <- ggplot(stars)+
160+
geom_polygon(aes(x, y, group=group))
161+
162+
test_that("geom_polygon(aes(group)) -> 1 trace", {
163+
info <- expect_traces(star.group, 1, "star-group")
164+
tr <- info$traces[[1]]
165+
expect_equal(tr$fill, "tozerox")
166+
expect_equal(tr$x,
167+
c(0, -1, 2, -2, 1, 0, NA,
168+
10, 9, 12, 8, 11, 10, NA,
169+
0, 0))
170+
expect_equal(tr$y,
171+
c(2, 0, 1, 1, 0, 2, NA,
172+
2, 0, 1, 1, 0, 2, NA,
173+
2, 2))
174+
})
175+
176+
star.group.color <- ggplot(stars)+
177+
geom_polygon(aes(x, y, group=group), color="red")
178+
179+
test_that("geom_polygon(aes(group), color) -> 1 trace", {
180+
info <- expect_traces(star.group.color, 1, "star-group-color")
181+
tr <- info$traces[[1]]
182+
expect_equal(tr$fill, "tozerox")
183+
expect_equal(tr$line$color, toRGB("red"))
184+
expect_equal(tr$x,
185+
c(0, -1, 2, -2, 1, 0, NA,
186+
10, 9, 12, 8, 11, 10, NA,
187+
0, 0))
188+
expect_equal(tr$y,
189+
c(2, 0, 1, 1, 0, 2, NA,
190+
2, 0, 1, 1, 0, 2, NA,
191+
2, 2))
192+
})
193+
194+
star.fill.color <- ggplot(stars)+
195+
geom_polygon(aes(x, y, group=group, fill=group), color="black")
196+
197+
test_that("geom_polygon(aes(group, fill), color) -> 2 trace", {
198+
info <- expect_traces(star.fill.color, 2, "star-fill-color")
199+
tr <- info$traces[[1]]
200+
traces.by.name <- list()
201+
for(tr in info$traces){
202+
expect_equal(tr$line$color, toRGB("black"))
203+
expect_equal(tr$fill, "tozerox")
204+
expect_equal(tr$y, c(2, 0, 1, 1, 0, 2))
205+
traces.by.name[[tr$name]] <- tr
206+
}
207+
expect_equal(traces.by.name$left$x, c(0, -1, 2, -2, 1, 0))
208+
expect_equal(traces.by.name$right$x, c(10, 9, 12, 8, 11, 10))
209+
})

0 commit comments

Comments
 (0)