library(checkmate)
context("rErode")
test_that("output has class RasterLayer", {
input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
output <- rErode(obj = binarised)
expect_class(output, "RasterLayer")
})
test_that("dilate also non-binary input/kernel", {
input <- rtRasters$continuous
output <- rErode(obj = input)
expect_class(output, "RasterLayer")
output <- rErode(obj = input,
kernel = matrix(c(1, 1, 1, 1, 6, 1, 1, 1, 1), 3, 3))
expect_class(output, "RasterLayer")
})
test_that("output is named", {
input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
output <- rErode(obj = binarised)
expect_named(output)
})
test_that("output is binary", {
input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
output <- rErode(obj = binarised)
vals <- unique(values(output))
expect_set_equal(vals, c(0, 1))
})
test_that("output and input have same dimension", {
input <- rtRasters$continuous
dim1 <- dim(input)
binarised <- rBinarise(input, thresh = 30)
output <- rErode(obj = binarised)
expect_equal(dim(output), dim1)
})
test_that("Error if arguments have wrong value", {
input <- rtRasters$continuous
mat <- as.matrix(input)
binarised <- rBinarise(input, thresh = 30)
expect_error(rErode(obj = mat))
expect_error(rErode(obj = "bla"))
expect_error(rErode(obj = binarised, kernel = c(1, 2, 3)))
})
test_that("history is correct", {
input <- rtRasters$continuous
binarised <- rBinarise(input, thresh = 30)
output <- rErode(obj = binarised)
history <- output@history
expect_list(history, len = 3)
expect_equal(history[[3]], "the raster has been morphologically eroded")
binarised@history <- list()
output <- rErode(obj = binarised)
history <- output@history
expect_list(history, len = 2)
expect_equal(history[[2]], "the raster has been morphologically eroded")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.