diff --git a/tests/testthat/test-adj_range.R b/tests/testthat/test-adj_range.R index 6350ea1c..6e09a892 100644 --- a/tests/testthat/test-adj_range.R +++ b/tests/testthat/test-adj_range.R @@ -1,3 +1,5 @@ +library(data.table) + test_that("restrict_range() provides correct range", { test_noise <- as_OpenSpecy(x = seq(400,4000, by = 10), spectra = data.table(intensity = rnorm(361))) @@ -41,8 +43,9 @@ test_that("flatten_range() function test", { expect_false(all.equal(flat_map$spectra, tiny_map$spectra) |> isTRUE()) expect_equal(flat_map$spectra[1:20], tiny_map$spectra[1:20]) - expect_equal(flat_map$spectra[40:60, 1:5] |> unique() |> round(4), - data.table(-0.8694, -0.7769, -0.5828, -0.292, 0.1916)) + expect_equal(flat_map$spectra[40:60, 1:5] |> unique() |> round(4) + |> as.numeric(), + c(-0.8694, -1.246, -0.8304, -1.1909, -0.7857)) }) test_that("flatten_range() error handling", { diff --git a/tests/testthat/test-def_features.R b/tests/testthat/test-def_features.R index 5cf68c05..25fec60c 100644 --- a/tests/testthat/test-def_features.R +++ b/tests/testthat/test-def_features.R @@ -1,19 +1,19 @@ map <- read_extdata("CA_tiny_map.zip") |> read_any() test_that("features are identified when given logical", { - map$metadata$particles <- map$metadata$x == 0 + map$metadata$particles <- map$metadata$y == 0 id_map <- def_features(map, map$metadata$particles) - expect_true(length(unique(id_map$metadata$feature_id)) == 2) - expect_true(max(id_map$metadata$area, na.rm = T) == 13) - expect_true(max(id_map$metadata$feret_max, na.rm = T) == 13) + expect_length(unique(id_map$metadata$feature_id), 2) + expect_equal(max(id_map$metadata$area, na.rm = T), 13) + expect_equal(max(id_map$metadata$feret_max, na.rm = T), 13) }) test_that("particles are identified when given character", { - map$metadata$particles <- ifelse(map$metadata$x == 1, "particle", "not_particle") + map$metadata$particles <- ifelse(map$metadata$y == 1, "particle", "not_particle") id_map <- def_features(map, map$metadata$particles) - expect_true(length(unique(id_map$metadata$feature_id)) == 3) - expect_true(max(id_map$metadata$area, na.rm = T) == 182) - expect_true(round(max(id_map$metadata$feret_max, na.rm = T)) == 19) + expect_length(unique(id_map$metadata$feature_id), 3) + expect_equal(max(id_map$metadata$area, na.rm = T), 182) + expect_equal(round(max(id_map$metadata$feret_max, na.rm = T)), 19) }) test_that("an error is thrown for invalid feature input", { @@ -46,21 +46,21 @@ test_that("the original spectrum remains unmodified and metadata is amended", { }) test_that("collapse particles returns expected values", { - particles <- ifelse(map$metadata$x == 1, "particleA", "particleB") + particles <- ifelse(map$metadata$y == 1, "particleA", "particleB") id_map <- def_features(map, particles) test_collapsed <- collapse_spec(id_map) expect_equal(test_collapsed$metadata |> nrow(), 3) expect_equal(test_collapsed$metadata$feret_max |> round(2), c(13, 13, 18.69)) - expect_equal(test_collapsed$metadata$centroid_y |> unique(), 6) + expect_equal(test_collapsed$metadata$centroid_x |> unique(), 6) - particles <- map$metadata$x == 1 + particles <- map$metadata$y == 1 id_map <- def_features(map, particles) test_collapsed <- collapse_spec(id_map) expect_equal(test_collapsed$metadata |> nrow(), 2) expect_equal(test_collapsed$metadata$feret_max |> round(2), c(NA, 13)) - expect_equal(test_collapsed$metadata$centroid_y |> unique(), 6) + expect_equal(test_collapsed$metadata$centroid_x |> unique(), 6) expect_contains(names(test_collapsed$metadata), c("feature_id", "area", "feret_max", "centroid_y", diff --git a/tests/testthat/test-read_envi.R b/tests/testthat/test-read_envi.R index df7f2b1d..dc48dad4 100644 --- a/tests/testthat/test-read_envi.R +++ b/tests/testthat/test-read_envi.R @@ -1,5 +1,5 @@ test_that("ENVI files are read", { - expect_message(tiny_map <- read_zip(read_extdata("CA_tiny_map.zip"))) + tiny_map <- read_zip(read_extdata("CA_tiny_map.zip")) expect_s3_class(tiny_map, "OpenSpecy") expect_equal(ncol(tiny_map$spectra), 208)