-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
## Data for tests ---- | ||
|
||
df <- data.frame(matrix(rep(1, 21), nrow = 1)) | ||
colnames(df) <- get_required_columns() | ||
|
||
df <- rbind(df, df, df, df, df) | ||
|
||
df[ , "site_lat_start_decimal"] <- c( 45.26, 34.18, -04.56, NA, -04.56) | ||
df[ , "site_lon_start_decimal"] <- c(-34.25, -48.29, 74.01, 74.01, NA) | ||
|
||
bbox_num <- c(-64.48, 16.05, -10.16, 54.08) | ||
|
||
bbox <- sf::st_bbox(c(xmin = bbox_num[1], ymin = bbox_num[2], | ||
xmax = bbox_num[3], ymax = bbox_num[4]), | ||
crs = sf::st_crs(4326)) | ||
|
||
bbox_0 <- sf::st_bbox(c(xmin = bbox_num[1], ymin = bbox_num[2], | ||
xmax = bbox_num[3], ymax = bbox_num[4]), | ||
crs = NA) | ||
|
||
bbox_num_2 <- c(64.48, 16.05, 10.16, 54.08) | ||
|
||
|
||
## filter_by_bbox() ---- | ||
|
||
test_that("Test filter_by_bbox() for error", { | ||
|
||
expect_error(filter_by_bbox(df), | ||
"Argument 'bbox' is required", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_bbox(df, 1), | ||
"The object 'bbox' must a numeric of length 4 or a bbox object", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_bbox(df, iho_boundaries), | ||
"The object 'bbox' must a numeric of length 4 or a bbox object", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_bbox(df, bbox_0), | ||
"The object 'bbox' must have a CRS", | ||
fixed = TRUE) | ||
}) | ||
|
||
|
||
test_that("Test filter_by_bbox() for success", { | ||
|
||
expect_silent(df_sub <- filter_by_bbox(df, bbox_num)) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 2L) | ||
|
||
expect_silent(df_sub <- filter_by_bbox(df, bbox)) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 2L) | ||
|
||
expect_silent(df_sub <- filter_by_bbox(df, bbox_num_2)) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 0L) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## Data for tests ---- | ||
|
||
df <- data.frame(matrix(rep(1, 21), nrow = 1)) | ||
colnames(df) <- get_required_columns() | ||
|
||
df <- rbind(df, df, df, df, df) | ||
|
||
df[ , "site_lat_start_decimal"] <- c( 45.26, 34.18, -04.56, NA, -04.56) | ||
df[ , "site_lon_start_decimal"] <- c(-34.25, -48.29, 74.01, 74.01, NA) | ||
|
||
|
||
|
||
## filter_by_ocean() ---- | ||
|
||
test_that("Test filter_by_ocean() for error", { | ||
|
||
expect_error(filter_by_ocean(df), | ||
"Argument 'ocean' is required", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_ocean(df, 1), | ||
"Argument 'ocean' must be a character of length >= 1", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_ocean(df, "Indian"), | ||
paste0("Some ocean names are mispelled. Please use ", | ||
"'get_ocean_names()' to find the correct spelling"), | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_ocean(df, c("Indian", "Arctic Ocean")), | ||
paste0("Some ocean names are mispelled. Please use ", | ||
"'get_ocean_names()' to find the correct spelling"), | ||
fixed = TRUE) | ||
}) | ||
|
||
|
||
test_that("Test filter_by_ocean() for success", { | ||
|
||
expect_silent(df_sub <- filter_by_ocean(df, "Indian Ocean")) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 1L) | ||
|
||
expect_silent(df_sub <- filter_by_ocean(df, "North Atlantic Ocean")) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 2L) | ||
|
||
expect_silent(df_sub <- filter_by_ocean(df, "South Atlantic Ocean")) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 0L) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
## Data for tests ---- | ||
|
||
df <- data.frame(matrix(rep(1, 21), nrow = 1)) | ||
colnames(df) <- get_required_columns() | ||
|
||
df <- rbind(df, df, df, df, df) | ||
|
||
df[ , "site_lat_start_decimal"] <- c( 45.26, 34.18, -04.56, NA, -04.56) | ||
df[ , "site_lon_start_decimal"] <- c(-34.25, -48.29, 74.01, 74.01, NA) | ||
|
||
pol <- iho_boundaries[1, ] | ||
|
||
pol_1 <- pol | ||
sf::st_crs(pol_1) <- NA | ||
|
||
pts <- data_to_sf(df) | ||
|
||
|
||
## filter_by_polygon() ---- | ||
|
||
test_that("Test filter_by_polygon() for error", { | ||
|
||
expect_error(filter_by_polygon(df), | ||
"Argument 'polygon' is required", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_polygon(df, df), | ||
"Argument 'polygon' must be an 'sf' object", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_polygon(df, pts), | ||
"Argument 'polygon' must be a 'POLYGON' or a 'MULTIPOLYGON'", | ||
fixed = TRUE) | ||
|
||
expect_error(filter_by_polygon(df, pol_1), | ||
"The object 'polygon' must have a CRS", | ||
fixed = TRUE) | ||
}) | ||
|
||
test_that("Test filter_by_polygon() for success", { | ||
|
||
expect_silent(df_sub <- filter_by_polygon(df, iho_boundaries[2, ])) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 1L) | ||
|
||
expect_silent(df_sub <- filter_by_polygon(df, iho_boundaries[4, ])) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 2L) | ||
|
||
expect_silent(df_sub <- filter_by_polygon(df, iho_boundaries[1, ])) | ||
|
||
expect_true(is.data.frame(df_sub)) | ||
expect_equal(ncol(df_sub), ncol(df)) | ||
expect_equal(nrow(df_sub), 0L) | ||
}) |