@@ -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+
1826test_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
253282test_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
520589test_that(" cosewic_plot()" , {
521590 expect_silent(r1 <- cosewic_ranges(bcch , crs = 3347 ))
0 commit comments