Skip to content

Commit

Permalink
test: unit tests for ggplot2
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Feb 14, 2024
1 parent e1530e4 commit bc49107
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/geom_basemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ geom_basemap <- function() {

list(
geom_sf(data = ne_oceans, fill = "#cdeafc", col = "#cdeafc",
linewidth = 0.10) +
linewidth = 0.10),
geom_sf(data = ne_graticules, col = "#bae2fb",
linewidth = 0.10) +
linewidth = 0.10),
geom_sf(data = ne_countries, fill = "#a6a6a6", col = "#b1b1b1",
linewidth = 0.10) +
linewidth = 0.10),
geom_sf(data = ne_bbox, fill = NA, col = "#a6a6a6",
linewidth = 0.75) +
linewidth = 0.75),
theme_void()
)
}
31 changes: 31 additions & 0 deletions tests/testthat/test-data_to_sf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Data for tests ----

df <- data.frame(matrix(1:21, nrow = 1))
colnames(df) <- get_required_columns()

df_w_na <- rbind(df, df, df, df)
df_w_na[2, "site_lon_start_decimal"] <- NA
df_w_na[3, "site_lat_start_decimal"] <- NA
df_w_na[4, "site_lon_start_decimal"] <- NA
df_w_na[4, "site_lat_start_decimal"] <- NA



## data_to_sf() ----

test_that("Test data_to_sf() for success", {

df_sf <- data_to_sf(df)

expect_true(is.data.frame(df_sf))
expect_true(inherits(df_sf, "sf"))
expect_equal(ncol(df_sf), 20L)
expect_equal(nrow(df_sf), 1L)

expect_length(grep("robin", as.character(sf::st_crs(df_sf))), 1L)

expect_equal(as.character(unique(sf::st_geometry_type(df_sf))), "POINT")

df_sf <- data_to_sf(df_w_na)
expect_equal(nrow(df_sf), 1L)
})
19 changes: 19 additions & 0 deletions tests/testthat/test-geom_basemap.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## geom_basemap() ----

test_that("Test geom_basemap() for success", {

expect_silent({ geom <- geom_basemap() })

expect_true("list" %in% class(geom))
expect_equal(length(geom), 5L)

for (i in 1:4) {
expect_true("Layer" %in% class(geom[[i]][[1]]))
expect_true("LayerInstance" %in% class(geom[[i]][[1]]))
expect_true("ggproto" %in% class(geom[[i]][[1]]))
expect_true("gg" %in% class(geom[[i]][[1]]))
expect_true("LayerSf" %in% class(geom[[i]][[1]]))
}

expect_true("element_blank" %in% class(geom[[5]][[1]]))
})
15 changes: 15 additions & 0 deletions tests/testthat/test-map_distribution.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Data for tests ----

df <- data.frame(matrix(1:21, nrow = 1))
colnames(df) <- get_required_columns()


## map_distribution() ----

test_that("Test map_distribution() for success", {

expect_silent({ gg <- map_distribution(df) })

expect_true("gg" %in% class(gg))
expect_true("ggplot" %in% class(gg))
})

0 comments on commit bc49107

Please sign in to comment.