|
| 1 | +test_that("Header mutual_clustering_score matches MutualClusteringInfo", { |
| 2 | + skip_if_not_installed("TreeDist") |
| 3 | + library(TreeTools) |
| 4 | + library(TreeDist) |
| 5 | + |
| 6 | + bal8 <- BalancedTree(8) |
| 7 | + pec8 <- PectinateTree(8) |
| 8 | + star8 <- StarTree(8) |
| 9 | + |
| 10 | + tips <- TipLabels(bal8) |
| 11 | + n_tip <- length(tips) |
| 12 | + splits_bal <- as.Splits(bal8, tips) |
| 13 | + splits_pec <- as.Splits(pec8, tips) |
| 14 | + splits_star <- as.Splits(star8, tips) |
| 15 | + |
| 16 | + # Score-only from the installable-header implementation |
| 17 | + impl_score <- TreeDist:::cpp_mci_impl_score |
| 18 | + |
| 19 | + impl_bal_pec <- impl_score(splits_bal, splits_pec, n_tip) |
| 20 | + impl_bal_bal <- impl_score(splits_bal, splits_bal, n_tip) |
| 21 | + impl_star <- impl_score(splits_bal, splits_star, n_tip) |
| 22 | + |
| 23 | + # Reference from MutualClusteringInfo (unnormalized score) |
| 24 | + ref_bal_pec <- MutualClusteringInfo(bal8, pec8) |
| 25 | + ref_bal_bal <- MutualClusteringInfo(bal8, bal8) |
| 26 | + |
| 27 | + expect_equal(impl_bal_pec, ref_bal_pec, tolerance = 1e-10) |
| 28 | + expect_equal(impl_bal_bal, ref_bal_bal, tolerance = 1e-10) |
| 29 | + expect_equal(impl_star, 0) |
| 30 | +}) |
| 31 | + |
| 32 | +test_that("Header MCI covers exact-match early exit and partial LAP", { |
| 33 | + skip_if_not_installed("TreeDist") |
| 34 | + library(TreeTools) |
| 35 | + library(TreeDist) |
| 36 | + impl_score <- TreeDist:::cpp_mci_impl_score |
| 37 | + |
| 38 | + # Two identical trees → all splits match exactly (early exit path) |
| 39 | + bal20 <- BalancedTree(20) |
| 40 | + tips <- TipLabels(bal20) |
| 41 | + n_tip <- length(tips) |
| 42 | + splits20 <- as.Splits(bal20, tips) |
| 43 | + |
| 44 | + result <- impl_score(splits20, splits20, n_tip) |
| 45 | + expect_equal(result, MutualClusteringInfo(bal20, bal20), tolerance = 1e-10) |
| 46 | + |
| 47 | + # Trees that share some but not all splits → partial match + LAP |
| 48 | + pec20 <- PectinateTree(20) |
| 49 | + splits_pec20 <- as.Splits(pec20, tips) |
| 50 | + |
| 51 | + result2 <- impl_score(splits20, splits_pec20, n_tip) |
| 52 | + expect_equal(result2, MutualClusteringInfo(bal20, pec20), tolerance = 1e-10) |
| 53 | +}) |
0 commit comments