library(checkmate)
context("rSubstitute")
test_that("output has class RasterLayer", {
input <- rtRasters$continuous
output <- rSubstitute(input, old = c(41:47), new = list(id = 40))
expect_class(output, "RasterLayer")
})
test_that("output is named", {
input <- rtRasters$continuous
output <- rSubstitute(input, old = c(41:47), new = list(id = 40))
expect_named(output)
})
test_that("output and input have same dimension", {
input <- rtRasters$continuous
dim1 <- dim(input)
output <- rSubstitute(input, old = c(41:47), new = list(id = 40))
expect_equal(dim(output), dim1)
})
test_that("Error if arguments have wrong value", {
input <- rtRasters$continuous
mat <- as.matrix(input)
expect_error(rSubstitute(input))
expect_error(rSubstitute(input, old = c(41:47)))
expect_error(rSubstitute(mat, old = c(41:47), new = 40))
expect_error(rSubstitute("bla", old = c(41:47), new = 40))
expect_error(rSubstitute(input, old = c(41:47), new = 40.1))
expect_error(rSubstitute(input, old = 41.1, new = 40))
expect_error(rSubstitute(input, old = 41.1, new = "bla"))
expect_error(rSubstitute(input, old = "bla", new = 40))
})
test_that("history is correct", {
input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
output <- rSubstitute(input, old = c(41:47), new = list(id = 40))
history <- output@history
expect_list(history, len = 2, types = "character")
output <- rSubstitute(binarised, old = 1, new = list(id = 2))
history <- output@history
expect_list(history, len = 3, types = "character")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.