Skip to content

Commit

Permalink
moar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wcornwell committed Nov 18, 2024
1 parent ea8577d commit d6a0cd9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
32 changes: 32 additions & 0 deletions tests/testthat/test-drone_process.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set.seed(123)
ndvi_values <- data.frame(site = rep(c("site_one", "site_two"), each = 100),
point = rep(1:100, times = 2),
ndvi = runif(200, min = -1, max = 1),
class = sample(rep(c('veg', 'non-veg'), each = 100)))


test_that("find_optimum_thresholds works", {
ndvi_thresholds <- find_optimum_thresholds(ndvi_values,
class_col = 'class', band_or_index_col = 'ndvi',
site_col = 'site', class_value = 'non-veg')
expect_true(ndvi_thresholds$threshold[1] > -1)
expect_true(ndvi_thresholds$threshold[1] < 1)
})



test_that("extract_pixel_values works", {
aoi_files <- list.files(
system.file("extdata/fishnet", package = "saltbush"),
pattern = '_fishnet.shp$', full.names = TRUE
)
raster_files <- list.files(
system.file("extdata/multiband_image", package = "saltbush"),
pattern = '.tif$', full.names = TRUE
)
pixelvalues <- extract_pixel_values(
raster_files, aoi_files, c('blue', 'green', 'red', 'red_edge', 'nir')
)
expect_true(dim(pixelvalues)[1] > 20000)
expect_true(mean(pixelvalues[,3]) > 0.05 & mean(pixelvalues[,3]) < 0.06)
})
16 changes: 1 addition & 15 deletions tests/testthat/test-test_spectral.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,5 @@ test_that("calculate_spectral_metrics works", {
expect_type(spectral_metrics_no_rare,"list")
})

test_that("extract_pixel_values works", {
aoi_files <- list.files(
system.file("extdata/fishnet", package = "saltbush"),
pattern = '_fishnet.shp$', full.names = TRUE
)
raster_files <- list.files(
system.file("extdata/multiband_image", package = "saltbush"),
pattern = '.tif$', full.names = TRUE
)
pixelvalues <- extract_pixel_values(
raster_files, aoi_files, c('blue', 'green', 'red', 'red_edge', 'nir')
)
expect_true(dim(pixelvalues)[1] > 20000)
expect_true(mean(pixelvalues[,3]) > 0.05 & mean(pixelvalues[,3]) < 0.06)
})


0 comments on commit d6a0cd9

Please sign in to comment.