Skip to content

Commit

Permalink
Adjusting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoVilela committed Aug 3, 2023
1 parent b915955 commit 80ad43b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 41 deletions.
Binary file modified .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion R/lets_presab_birds.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#' @description Convert species' ranges (in shapefile format and stored in
#' particular folders) into a presence-absence matrix based on a user-defined
#' grid. This function is specially designed to work with BirdLife Intl.
#' shapefiles (\url{https://www.birdlife.org}).
#' shapefiles (\url{https://www.birdlife.org}). (Notice that new versions of
#' birds spatial data are in a similar format to other groups and should be
#' run using the lets.presab function. We will keep this function in case
#' someone needs to use on the previous data format.)
#'
#' @inheritParams lets.presab
#' @param path Path location of folders with one or more species' individual
Expand Down
5 changes: 4 additions & 1 deletion man/lets.presab.birds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified tests/.DS_Store
Binary file not shown.
17 changes: 0 additions & 17 deletions tests/testthat/test-lets_distmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,3 @@ test_that("lets.distmat works fine, asdist = FALSE", {
})


test_that("lets.distmat works fine, miles = TRUE", {


distPAM <- lets.distmat(PAM, miles = TRUE)
expect_true(class(distPAM)[1] == "dist")
expect_true(all(dim(as.matrix(distPAM)) == dimPAM))

})

test_that("lets.distmat works fine, xy as matrix ", {


distPAM <- lets.distmat(coords, miles = TRUE)
expect_true(class(distPAM)[1] == "dist")
expect_true(all(dim(as.matrix(distPAM)) == nrow(coords)))

})
4 changes: 2 additions & 2 deletions tests/testthat/test-lets_gridirizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("lets.gridirizer works fine", {
resu_test <- lets.gridirizer(PAM)

expect_equal(class(resu_test)[1], "list")
expect_true(inherits(resu_test[[1]], "SpatialPolygonsDataFrame"))
expect_equal(class(resu_test[[2]])[1], "matrix")
expect_true(inherits(resu_test[[1]], "SpatVector"))
expect_equal(class(resu_test[[2]])[1], "data.frame")

})
2 changes: 1 addition & 1 deletion tests/testthat/test-lets_maplizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("lets.maplizer works fine", {
resu_test <- lets.maplizer(PAM, trait, PAM$S, ras = TRUE)
expect_equal(class(resu_test)[1], "list")
expect_equal(class(resu_test[[1]])[1], "matrix")
expect_true(inherits(resu_test[[2]], "RasterLayer"))
expect_true(inherits(resu_test[[2]], "SpatRaster"))

expect_true(ncol(resu_test[[1]]) == 3)
})
34 changes: 24 additions & 10 deletions tests/testthat/test-lets_presab.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ data(Phyllomedusa)

test_that("lets.presab return a correct PresenceAbsence object", {
skip_on_cran()
PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)
PAM <-
lets.presab(
Phyllomedusa,
xmn = -93,
xmx = -29,
ymn = -57,
ymx = 15,
resol = 1,
remove.cells = TRUE,
remove.sp = TRUE,
show.matrix = FALSE,
crs = terra::crs("+proj=longlat +datum=WGS84"),
cover = 0,
presence = NULL,
origin = NULL,
seasonal = NULL,
count = FALSE
)
expect_equal(class(PAM), "PresenceAbsence")
expect_true(is.matrix(PAM[[1]]))
expect_true(inherits(PAM[[2]], "SpatRaster"))
Expand All @@ -21,7 +35,7 @@ test_that("lets.presab return a correct PresenceAbsence object for the world", {

PAM <- lets.presab(Phyllomedusa, resol=5, remove.cells=TRUE,
remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"),
crs=terra::crs("+proj=longlat +datum=WGS84"),
cover=0, presence=NULL, origin=NULL,
seasonal=NULL, count=FALSE)

Expand All @@ -40,7 +54,7 @@ test_that("lets.presab return a correct PresenceAbsence object (count=TRUE)", {

PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=TRUE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -57,7 +71,7 @@ test_that("lets.presab return a correct PresenceAbsence object, cover=0.2", {

PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -74,7 +88,7 @@ test_that("lets.presab return a correct PresenceAbsence object different project
pro <- paste("+proj=eqdc +lat_0=-32 +lon_0=-60 +lat_1=-5",
"+lat_2=-42 +x_0=0 +y_0=0 +ellps=aust_SA",
"+units=m +no_defs")
SA_EC <- CRS(pro)
SA_EC <- terra::crs(pro)
PAM_proj <- lets.presab(shapes = Phyllomedusa,
xmn = -4135157,
xmx = 4707602,
Expand All @@ -97,7 +111,7 @@ test_that("lets.presab return a correct PresenceAbsence object, remove.sp=FALSE"

PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15,
resol=1, remove.cells=TRUE, remove.sp=FALSE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -117,7 +131,7 @@ test_that("lets.presab return a correct PresenceAbsence object, remove.cells=FAL

PAM <- lets.presab(Phyllomedusa, xmn=-93, xmx=-29, ymn= -57, ymx=15,
resol=1, remove.cells=FALSE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-lets_presab_birds.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object", {
skip_on_cran()
PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM)[1], "PresenceAbsence")
Expand All @@ -21,7 +21,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object for the wor
skip_on_cran()

PAM <- lets.presab.birds(path.Ramphastos, resol=5, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -38,7 +38,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object for cover d
pro <- paste("+proj=eqdc +lat_0=-32 +lon_0=-60 +lat_1=-5",
"+lat_2=-42 +x_0=0 +y_0=0 +ellps=aust_SA",
"+units=m +no_defs")
SA_EC <- suppressWarnings(CRS(pro))
SA_EC <- suppressWarnings(terra::crs(pro))

PAM3 <- lets.presab.birds(path.Ramphastos, xmn = -4135157,
xmx = 4707602,
Expand All @@ -60,7 +60,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object (count=TRUE

PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=TRUE)
expect_equal(class(PAM), "PresenceAbsence")
expect_true(is.matrix(PAM[[1]]))
Expand All @@ -74,7 +74,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object, cover=0.2"

PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25,
resol=1, remove.cells=TRUE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0.2, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -92,7 +92,7 @@ test_that("lets.presab.birds return a correct PresenceAbsence object,

PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25,
resol=1, remove.cells=TRUE, remove.sp=FALSE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover = 0.999999, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover = 0.999999, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)
expect_equal(class(PAM), "PresenceAbsence")
expect_true(is.matrix(PAM[[1]]))
Expand All @@ -106,7 +106,7 @@ test_that("lets.presab.birdsreturn a correct PresenceAbsence object, remove.cell

PAM <- lets.presab.birds(path.Ramphastos, xmn=-93, xmx=-29, ymn= -57, ymx=25,
resol=1, remove.cells=FALSE, remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0, presence=NULL,
origin=NULL, seasonal=NULL, count=FALSE)

expect_equal(class(PAM), "PresenceAbsence")
Expand All @@ -124,12 +124,12 @@ test_that("lets.presab.birdsreturn a correct PresenceAbsence object, remove.cell

test_that("lets.presab.birds new projection", {
skip_on_cran()
desiredcrs <- CRS("+proj=laea +lat_0=0 +lon_0=-80 +x_0=180 +y_0=70 +units=km")
desiredcrs <- terra::crs("+proj=laea +lat_0=0 +lon_0=-80 +x_0=180 +y_0=70 +units=km")
PAM <- lets.presab.birds(path.Ramphastos, xmn = -3000,
xmx = 6000, ymn = -5000,
ymx = 3000, res = 100, remove.cells=TRUE,
remove.sp=TRUE, show.matrix=FALSE,
crs=CRS("+proj=longlat +datum=WGS84"), cover=0,
crs=terra::crs("+proj=longlat +datum=WGS84"), cover=0,
presence=NULL,
crs.grid = desiredcrs,
origin=NULL, seasonal=NULL, count=TRUE)
Expand Down

0 comments on commit 80ad43b

Please sign in to comment.