-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-source-data-helpers.R
51 lines (36 loc) · 1.2 KB
/
test-source-data-helpers.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
test_that("Data is pulled from a ggplot2 object", {
p <- ggplot(diamonds, aes(x = carat, y = cut)) +
geom_point()
expect_equal(pull_original_plot_data(p), diamonds)
})
test_that("Data is pulled from a wrapped ggplot2 object.", {
p1 <- ggplot(diamonds, aes(x = caret, y = cut)) +
geom_point()
p2 <- ggplot(diamonds, aes(x = depth, y = price)) +
geom_col()
p <- patchwork::wrap_plots(p1, p2)
tbl <- pull_wrapped_plot_data(p, number, c("1", "2"))
expected_tbl <- bind_rows(
diamonds %>% mutate(number = "1"),
diamonds %>% mutate(number = "2")
)
expect_equal(tbl, expected_tbl)
})
test_that("The correct source data file path is created", {
expect_null(get_source_data_filename(1))
expect_equal(
get_source_data_filename(42, "a"),
file.path(SOURCE_DATA_BASE_DIR, "figure-01", "panel-a.tsv")
)
expect_equal(
get_source_data_filename(42),
file.path(SOURCE_DATA_BASE_DIR, "figure-01", "data.tsv")
)
expect_equal(
get_source_data_filename(41),
file.path(SOURCE_DATA_BASE_DIR, "supplementary-figure-06", "data.tsv")
)
})
test_that("The directory name is extracted from a file path.", {
expect_equal(get_directory("a/b/c/d.tsv"), "a/b/c/")
})