Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zsteinmetz committed Oct 23, 2023
1 parent b3a59c2 commit cb14818
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
5 changes: 2 additions & 3 deletions tests/testthat/test-adj_range.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ 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)
|> as.numeric(),
c(-0.8694, -1.246, -0.8304, -1.1909, -0.7857))
flat_map$spectra[40:60, 1:5] |> unique() |> round(4) |> as.numeric() |>
expect_equal(c(-0.8694, -0.7769, -0.5828, -0.2920, 0.1916))
})
46 changes: 29 additions & 17 deletions tests/testthat/test-def_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,27 @@ test_that("collapse_spec() handles input errors correctly", {
test_that("features are identified when given logical", {
map$metadata$particles <- map$metadata$y == 0
id_map <- def_features(map, map$metadata$particles)
expect_true(check_OpenSpecy(id_map))
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)
expect_equal(max(id_map$metadata$feret_min, na.rm = T), 1)
expect_equal(max(id_map$metadata$perimeter, na.rm = T), 24)
check_OpenSpecy(id_map) |> expect_true()
unique(id_map$metadata$feature_id) |> expect_length(2)
max(id_map$metadata$area, na.rm = T) |> expect_equal(16)
max(id_map$metadata$feret_max, na.rm = T) |> round(2) |>
expect_equal(13.04)
max(id_map$metadata$feret_min, na.rm = T) |> round(2) |>
expect_equal(1.23)
max(id_map$metadata$perimeter, na.rm = T) |> round(2) |>
expect_equal(25.05)
})

test_that("particles are identified when given character", {
map$metadata$particles <- ifelse(map$metadata$y == 1, "particle", "not_particle")
id_map <- def_features(map, map$metadata$particles)
expect_true(check_OpenSpecy(id_map))
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)
unique(id_map$metadata$feature_id) |>
expect_length(3)
max(id_map$metadata$area, na.rm = T) |>
expect_equal(176)
max(id_map$metadata$feret_max, na.rm = T) |> round(2) |>
expect_equal(18.69)
})

test_that("an error is thrown for invalid feature input", {
Expand Down Expand Up @@ -72,20 +78,26 @@ test_that("collapse particles returns expected values", {

expect_true(check_OpenSpecy(test_collapsed))

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_x |> unique(), 6)
test_collapsed$metadata |> nrow() |>
expect_equal(3)
test_collapsed$metadata$feret_max |> round(2) |>
expect_equal(c(13.04, 13.04, 18.69))
test_collapsed$metadata$centroid_x |> unique() |>
expect_equal(7.5)

particles <- map$metadata$y == 1
id_map <- def_features(map, particles)
expect_true(check_OpenSpecy(id_map))

test_collapsed <- collapse_spec(id_map)
expect_true(check_OpenSpecy(test_collapsed))

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_x |> unique(), 6)
check_OpenSpecy(test_collapsed) |> expect_true()

test_collapsed$metadata |> nrow() |>
expect_equal(2)
test_collapsed$metadata$feret_max |> round(2) |>
expect_equal(c(NA, 13.04))
test_collapsed$metadata$centroid_x |> unique() |>
expect_equal(7.5)

expect_contains(names(test_collapsed$metadata),
c("feature_id", "area", "feret_max", "centroid_y",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-read_envi.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("ENVI files are read", {
range(tiny_map$spectra) |> round(2) |>
expect_equal(c(-1.32, 1.17))
tiny_map$spectra[c(1,427), c(1,45)] |> round(2) |> unlist() |> as.numeric() |>
expect_equal(c(-0.86, -0.88, -0.62, -0.64))
expect_equal(c(-0.86, -0.88, 0.11, -0.39))

names(tiny_map$metadata) |>
expect_contains(c("x", "y", "file_name", "file_id", "description",
Expand Down

0 comments on commit cb14818

Please sign in to comment.