tests/testthat/test-calc_H.R

df1 <- data.frame(station = c("1","1","1","2","2","2"),
                  species = c("Acidostoma neglectum",
                              "Acar botanica",
                              "Acrocirrus validus",
                              "Acteocina bullata",
                              "Austrohelice crassa",
                              "Capitella nonatoi"),
                  count = c(1, 2, 4, 5, 3, 7))


test_that("H' with zeroes H", {
  H <- ambiR::Hdash(df1)$H
  expect_equal(round(H$H, 6), 2.367795)
})

test_that("H' with zeroes N", {
  H <- ambiR::Hdash(df1)$H
  expect_equal(H$N, 22)
})

df2 <- data.frame(station = c("1","1","1","2","2","2","2"),
                 species = c("Acidostoma neglectum",
                             "Acar botanica",
                             "Acrocirrus validus",
                             "Acteocina bullata",
                             "Austrohelice crassa",
                             "Capitella nonatoi",
                             "this is not a species"),
                 count = c(1, 2, 4, 5, 3, 7, 4))

test_that("H' with missing H", {
  H <- ambiR::Hdash(df2)$H
  expect_equal(round(H$H, 6), 2.367795)
})

Try the ambiR package in your browser

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

ambiR documentation built on Dec. 20, 2025, 1:06 a.m.