context("four prong")

test_that("usage", {
  set.seed(42)
  focal_tree <- ape::rphylo(n = 4, birth = 1, death = 0)

  bal_tree <- treestats::create_fully_balanced_tree(focal_tree)

  c1 <- treestats::four_prong(bal_tree)
  testthat::expect_equal(c1, 0)

  ltab <- treestats::phylo_to_l(bal_tree)
  c2 <- treestats::four_prong(ltab)
  testthat::expect_equal(c2, 0)


  unbal_tree <- treestats::create_fully_unbalanced_tree(focal_tree)

  c1 <- treestats::four_prong(unbal_tree)
  testthat::expect_equal(c1, 1)

  ltab <- treestats::phylo_to_l(unbal_tree)
  c2 <- treestats::four_prong(ltab)
  testthat::expect_equal(c2, 1)
})

test_that("polytomies", {
  for (focal_tree in poly_trees) {
    res <- treestats::four_prong(focal_tree)
    testthat::expect_true(!is.na(res))
  }

  # now on artificial trees
  focal_tree <- ape::read.tree(text = "((((A:0.1,B:0.1):0.2,C:0.1):0.3,D:0.1):0.4,E:0.1);") # nolint
  res <- treestats::four_prong(focal_tree)
  testthat::expect_equal(res, 1)

  # now we create a poly
  focal_tree <- ape::read.tree(text = " ((((A:0.1,B:0.1,C:0.1):0.2,D:0.1):0.3,E:0.1):0.4);") # nolint
  res <- treestats::four_prong(focal_tree)
  testthat::expect_equal(res, 0)
})


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

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