Skip to content

Commit 766a554

Browse files
committed
Update tests
1 parent c0b635a commit 766a554

File tree

9 files changed

+87
-11
lines changed

9 files changed

+87
-11
lines changed

tests/testthat/_snaps/12_cosewic_tools/p-basic.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-map.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-no-cols-basic.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-no-cols-map.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-no-cols-mult.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-no-cols-points.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/_snaps/12_cosewic_tools/p-points.svg

Lines changed: 2 additions & 1 deletion
Loading

tests/testthat/test_08_downloads.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_that("Get counts for collections", {
1919
expect_s3_class(c1, "data.frame")
2020
expect_gt(nrow(c1), 0)
2121
expect_true(all(c1$collection %in% c("CBC", "BBS")))
22-
expect_true(all(c1$access %in% c("full", "no access")))
22+
expect_true(all(c1$access %in% c("full", "by request")))
2323

2424
expect_silent(
2525
c2 <- nc_count(
@@ -94,7 +94,7 @@ test_that("Counts return permissions", {
9494
sort(unique(c_sample_all[["access"]])),
9595
c("by request", "full", "no access")
9696
)
97-
expect_equal(sort(unique(c_sample_all[["akn_level"]])), 2:5)
97+
expect_true(all(c_sample_all[["akn_level"]] %in% c(NA, 2:5)))
9898
})
9999

100100
test_that("Counts error when no data returned", {
@@ -171,7 +171,7 @@ test_that("Data filters work as expected", {
171171
expect_equal(min(as.numeric(d1$survey_year), na.rm = TRUE), 2000)
172172
expect_equal(max(as.numeric(d1$survey_year), na.rm = TRUE), 2000)
173173

174-
# mult species/year
174+
# multiple species/year
175175
expect_silent(
176176
d2 <- nc_data_dl(
177177
collections = "ABBIRDRECS",
@@ -225,7 +225,7 @@ test_that("Filter region works as expected", {
225225
# IBA
226226
expect_silent(
227227
d <- nc_data_dl(
228-
region = list(iba = "AB001"),
228+
region = list(iba = "AB001"), years = 2000,
229229
username = "testuser",
230230
verbose = FALSE,
231231
info = "nc_test"

tests/testthat/test_12_cosewic_tools.R

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ test_that("prep_spatial() diff cols", {
1515
expect_equal(format(sf::st_crs(s)), "NAD83 / Statistics Canada Lambert")
1616
})
1717

18+
test_that("prep_spatial() projected", {
19+
b <- dplyr::rename(bcch, sp = species_id, rec = record_id)
20+
expect_error(
21+
prep_spatial(b, crs = 4326),
22+
"CRS is unprojected, area calculations should use a projected CRS"
23+
)
24+
})
25+
1826
test_that("cosewic_eoo()", {
1927
# Lambert
2028
df <- prep_spatial(bcch, crs = 3347)
@@ -249,6 +257,27 @@ test_that("cosewic_iao() no cols", {
249257
expect_snapshot_value(a, style = "json2")
250258
})
251259

260+
test_that("cosewic_iao() custom IAO grid", {
261+
grid <- sf::st_read(
262+
system.file(
263+
"extdata",
264+
"iao_bcch_grid.gpkg",
265+
package = "naturecounts"
266+
),
267+
quiet = TRUE
268+
)
269+
df <- prep_spatial(bcch, crs = "ESRI:102001")
270+
expect_message(
271+
a <- cosewic_iao(
272+
df,
273+
record = "record_id",
274+
spatial = FALSE,
275+
crs = "ESRI:102001",
276+
grid = grid
277+
),
278+
"User\\-provided grid has cell size of 2 \\[km\\]"
279+
)
280+
})
252281

253282
test_that("cosewic_ranges()", {
254283
# Lambert
@@ -516,6 +545,46 @@ test_that("cosewic_ranges() eoo clip", {
516545
expect_true(all(r0$eoo$eoo_p95 > r1$eoo$eoo_p95))
517546
})
518547

548+
test_that("cosewic_ranges() either", {
549+
expect_silent(s0 <- cosewic_ranges(bcch))
550+
expect_silent(s1 <- cosewic_ranges(bcch, which = "eoo"))
551+
expect_silent(s2 <- cosewic_ranges(bcch, which = "iao"))
552+
expect_equal(s0$eoo, s1$eoo)
553+
expect_equal(s0$iao, s2$iao)
554+
})
555+
556+
test_that("cosewic_ranges() errors/warnings if using unprojected CRS", {
557+
expect_error(
558+
cosewic_ranges(bcch, crs = 4326),
559+
"CRS is unprojected, area calculations should use a projected CRS"
560+
)
561+
})
562+
563+
564+
test_that("cosewic_ranges() custom IAO grid", {
565+
grid <- sf::st_read(
566+
system.file(
567+
"extdata",
568+
"iao_bcch_grid.gpkg",
569+
package = "naturecounts"
570+
),
571+
quiet = TRUE
572+
)
573+
expect_message(
574+
a <- cosewic_ranges(bcch, iao_grid = grid),
575+
"User\\-provided grid has cell size of 2 \\[km\\]"
576+
)
577+
expect_type(a, "list")
578+
expect_named(a, c("iao", "eoo"))
579+
expect_s3_class(a$iao, "sf")
580+
581+
# Error when grid is wrong CRS
582+
expect_error(
583+
cosewic_ranges(bcch, crs = 3347, iao_grid = grid),
584+
"`crs` must match the CRS of `iao\\_grid`"
585+
)
586+
})
587+
519588

520589
test_that("cosewic_plot()", {
521590
expect_silent(r1 <- cosewic_ranges(bcch, crs = 3347))

0 commit comments

Comments
 (0)