tests/testthat/test-fCover.R

context("fCover")

set.seed(42)
suppressPackageStartupMessages(library(raster))

data(lsat)
lc	  <- unsuperClass(lsat, nSamples = 50, nClass=3)$map
modis <- aggregate(lsat, 9)

for(cl in 1:2) {
    if (!identical(Sys.getenv("NOT_CRAN"), "true") && cl == 2) next
    
	test_that(sprintf("works for %s classes(s)",cl), {
				expect_is(fc <- fCover(
								classImage = lc ,
								predImage = modis,
								classes=1:cl,
								model="lm",
								nSample = 30,
								number = 5,
								tuneLength=1
						), c("RStoolbox", "fCover"))
				expect_equal(nlayers(fc$map), cl)
			})

}

test_that("errors and warnings are thrown",{
expect_error(fCover(
		classImage = lc ,
		predImage = modis,
		classes = 4,
		model="rf",
		nSample = 50,
		number = 5,
		tuneLength=1
),"One or more classes are not represented in the sampled pixels")
})

Try the RStoolbox package in your browser

Any scripts or data that you put into this service are public.

RStoolbox documentation built on March 18, 2022, 5:37 p.m.