context("mean I")

test_that("usage", {
  if (requireNamespace("treebalance")) {

    test_func <- function(phy) {
      # treebalance allows 'few' polytomies
      # but that is too hard to verify
      return(treebalance::IbasedI(phy, method = "mean",
                           correction = "prime", logs = FALSE))
    }

    standard_test(treestats::mean_i, test_func)
  }
})

test_that("polytomies", {
  for (focal_tree in poly_trees) {
    a1 <- try_stat(focal_tree, treestats::mean_i)
    testthat::expect_true(is.na(a1))
  }
})

test_that("abuse", {
  set.seed(42)
  focal_tree <- ape::rphylo(n = 3, birth = 1, death = 0)
  testthat::expect_warning(treestats::mean_i(focal_tree),
              "I statistic is only available for trees with at least 4 tips.")

  focal_ltab <- treestats::phylo_to_l(focal_tree)
  testthat::expect_warning(treestats::mean_i(focal_ltab),
              "I statistic is only available for trees with at least 4 tips.")
})

test_that("wrong_object", {
  testthat::expect_error(
    treestats::mean_i(10),
    "input object has to be phylo or ltable"
  )

  testthat::expect_error(
    treestats::mean_i(list()),
    "input object has to be phylo or ltable"
  )
})
