test_that("identical kernel estimates have zero divergence", { set.seed(11) x <- matrix(rnorm(80), ncol = 2) H <- diag(c(0.4, 0.5)) expect_equal(biv_kld(x, x, Hx = H, Hy = H, grid_size = 25), 0, tolerance = 1e-12) }) test_that("kernel estimator returns details and validates samples", { set.seed(12) x <- matrix(rnorm(80), ncol = 2) y <- matrix(rnorm(80, 0.25), ncol = 2) result <- biv_kld(x, y, bandwidth = "normal", grid_size = 25, details = TRUE) expect_s3_class(result, "bivkld_estimate") expect_true(is.finite(result$estimate)) expect_gte(result$estimate, 0) expect_error(biv_kld(x[, 1, drop = FALSE], y), "two columns") expect_error(biv_kld(rbind(x, c(NA, 0)), y), "finite") }) test_that("pairwise matrix is directed and has a zero diagonal", { set.seed(13) groups <- list( A = matrix(rnorm(80), ncol = 2), B = matrix(rnorm(80, 0.5), ncol = 2), C = matrix(rnorm(80, -0.2), ncol = 2) ) result <- biv_kld_matrix(groups, bandwidth = "normal", grid_size = 25) expect_s3_class(result, "bivkld_matrix") expect_equal(dim(result), c(3L, 3L)) expect_equal(unname(diag(result)), rep(0, 3)) expect_true(all(result >= 0)) expect_named(attr(result, "bandwidth"), names(groups)) })