Skip to content

Commit

Permalink
updating testthat v3
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalavi committed Jan 14, 2023
1 parent aa75b55 commit 17db9f0
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 504 deletions.
21 changes: 11 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ Imports:
sf (>= 1.0)
RoxygenNote: 7.2.1
Suggests:
terra (>= 1.6-41),
ggplot2 (>= 3.3.6),
dismo,
cowplot,
automap (>= 1.0-16),
shiny (>= 1.7),
knitr,
rmarkdown,
testthat,
covr
terra (>= 1.6-41),
ggplot2 (>= 3.3.6),
dismo,
cowplot,
automap (>= 1.0-16),
shiny (>= 1.7),
knitr,
rmarkdown,
testthat (>= 3.0.0),
covr
VignetteBuilder: knitr
Config/testthat/edition: 3
4 changes: 4 additions & 0 deletions R/spatialAutoRange.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#' }
#'
#' @export
#'
#' @examples
#' \donttest{
#' }
spatialAutoRange <- function(rasterLayer,
sampleNumber = 5000L,
border = NULL,
Expand Down
6 changes: 3 additions & 3 deletions blockCV.Rproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: No

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
Expand Down
16 changes: 14 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
comment: false
codecov:
token: 668a6472-722f-434d-9e77-0187bcb61a88

coverage:
token: 668a6472-722f-434d-9e77-0187bcb61a88
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
4 changes: 4 additions & 0 deletions man/spatialAutoRange.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/tests.html
# * https://testthat.r-lib.org/reference/test_package.html#special-files

library(testthat)
library(blockCV)

Expand Down
Binary file added tests/testthat/Rplots.pdf
Binary file not shown.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,76 +1,3 @@
library(blockCV)
library(automap)

context("Functions of v2")

awt <- system.file("extdata/au/", package = "blockCV") |>
list.files(full.names = TRUE) |>
terra::rast()
nl <- terra::nlyr(awt)

pa_data <- read.csv(system.file("extdata/", "species.csv", package = "blockCV")) |>
sf::st_as_sf(coords = c("x", "y"), crs = 7845)

# spatialAutoRange --------------------------------------------------------
expect_names <- c("range",
"rangeTable",
"plots",
"sampleNumber",
"variograms")


test_that("test spatialAutoRange function works", {
skip_on_cran()

range1 <- spatialAutoRange(rasterLayer = awt,
sampleNumber = 1000,
showPlots = TRUE)

expect_true(exists("range1"))
expect_is(range1, "SpatialAutoRange")
expect_equal(names(range1), expect_names)
expect_equal(nrow(range1$rangeTable), nl)
expect_equal(length(range1$variograms), nl)
expect_equal(dim(range1$rangeTable), c(nl, 3))
expect_is(range1$plots[[1]], "ggplot")
expect_is(range1$variograms[[1]], "autofitVariogram")
expect_is(range1$variograms, "list")
expect_is(range1$rangeTable, "data.frame")
expect_is(range1$sampleNumber, "numeric")
expect_is(range1$range, "numeric")
expect_true(range1$range >= 0)
expect_true(!is.null(range1$variograms))
expect_true(
all(names(awt) %in% range1$rangeTable$layers)
)

expect_equal(print.SpatialAutoRange(range1), "SpatialAutoRange")
expect_silent(plot.SpatialAutoRange(range1))
expect_output(summary.SpatialAutoRange(range1))

})

test_that("test spatialAutoRange function with x", {
skip_on_cran()

range3 <- spatialAutoRange(rasterLayer = awt,
speciesData = pa_data,
progress = FALSE,
showPlots = TRUE)

expect_true(exists("range3"))
expect_is(range3, "SpatialAutoRange")
expect_is(range3$plots[[1]], "ggplot")
expect_is(range3$variograms[[1]], "autofitVariogram")
expect_is(range3$range, "numeric")
expect_true(range3$range >= 0)
expect_true(!is.null(range3$variograms))

expect_equal(print.SpatialAutoRange(range3), "SpatialAutoRange")
expect_silent(plot.SpatialAutoRange(range3))

})

# library(blockCV)
#
# context("Spatial Autocorrelation Finder")
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-blocking.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
3 changes: 3 additions & 0 deletions tests/testthat/test-buffering.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
Loading

0 comments on commit 17db9f0

Please sign in to comment.