Skip to content

Commit 3aed0c4

Browse files
committed
Fix typo and add test for multiple hlines
1 parent 66d166a commit 3aed0c4

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

tests/testthat/test-ggplot-hline.R

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
context("Hline")
2-
32
# Horizontal line
43

5-
test_that("Second trace be the hline", {
6-
7-
x1 <- seq(from=0, to=3.5, by=0.5)
8-
x2 <- x1 * 0.95
9-
df <- data.frame("x1"=x1, "x2"=x2)
10-
11-
gg <- ggplot(df) + geom_point(aes(x=x1, y=x2)) +
12-
geom_hline(yintercept=1.1, colour="green", size=3)
4+
x1 <- seq(from=0, to=3.5, by=0.5)
5+
x2 <- x1 * 0.95
6+
df <- data.frame("x1"=x1, "x2"=x2)
7+
gg <- ggplot(df) + geom_point(aes(x=x1, y=x2))
8+
9+
test_that("second trace be the hline", {
10+
gg <- gg + geom_hline(yintercept=1.1, colour="green", size=3)
1311

1412
L <- gg2list(gg)
1513

1614
expect_equal(length(L), 3)
15+
expect_equal(L[[2]]$y[1], 1.1)
1716
expect_true(L[[2]]$x[1] <= 0)
1817
expect_true(L[[2]]$x[2] >= 3.5)
1918
expect_identical(L[[2]]$mode, "lines")
@@ -22,4 +21,23 @@ test_that("Second trace be the hline", {
2221
expect_identical(L[[2]]$line$color, "rgb(0,255,0)")
2322

2423
save_outputs(gg, "hline")
25-
})
24+
})
25+
26+
test_that("vector yintercept results in multiple horizontal lines", {
27+
gg <- gg + geom_hline(yintercept=1:3, colour="red", size=3)
28+
29+
L <- gg2list(gg)
30+
31+
expect_equal(length(L), 5)
32+
expect_equal(L[[2]]y[1], 1)
33+
expect_equal(L[[3]]y[1], 2)
34+
expect_equal(L[[4]]y[1], 3)
35+
expect_true(L[[4]]$x[1] <= 0)
36+
expect_true(L[[4]]$x[2] >= 3.325)
37+
expect_identical(L[[3]]$mode, "lines")
38+
expect_identical(L[[3]]$line$shape, "linear")
39+
expect_equal(L[[3]]$line$width, 3)
40+
expect_identical(L[[3]]$line$color, "rgb(255,0,0)")
41+
42+
save_outputs(gg, "hline-multiple")
43+
})

tests/testthat/test-ggplot-vline.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_that("second trace be the vline", {
1212
L <- gg2list(gg)
1313

1414
expect_equal(length(L), 3)
15-
expect_equal(L[[2]]x[1], 1.1)
15+
expect_equal(L[[2]]$x[1], 1.1)
1616
expect_true(L[[2]]$y[1] <= 0)
1717
expect_true(L[[2]]$y[2] >= 3.325)
1818
expect_identical(L[[2]]$mode, "lines")
@@ -23,7 +23,7 @@ test_that("second trace be the vline", {
2323
save_outputs(gg, "vline")
2424
})
2525

26-
test_that("vector yintercept results in multiple vertical lines", {
26+
test_that("vector xintercept results in multiple vertical lines", {
2727
gg <- gg + geom_vline(xintercept=1:2, colour="blue", size=3)
2828

2929
L <- gg2list(gg)

0 commit comments

Comments
 (0)