test_that("matrix batch agrees with independent fast dip tests", { set.seed(912) x <- cbind( Normal = rnorm(10000), Rounded = round(rnorm(10000), 1), Mixture = c(rnorm(5000, -1), rnorm(5000, 1)) ) batch <- fast_dip_test_matrix(x) expect_equal(batch$Column, seq_len(ncol(x))) expect_equal(batch$Distance, colnames(x)) for (j in seq_len(ncol(x))) { single <- fast_dip_test(x[, j]) expect_equal( batch$DipStatistic[[j]], unname(single$statistic), tolerance = 2e-15 ) expect_equal( batch$DipPValue[[j]], single$p.value, tolerance = 2e-14 ) } }) test_that("distance-analysis helper retains diptest below the threshold", { skip_if_not_installed("diptest") set.seed(913) features <- cbind(A = rnorm(5000), B = runif(5000)) observed <- BIDistances:::.distance_distribution_analysis_dip_tests( features, 1:2 ) expect_identical( observed$DipMethod, rep("diptest::dip.test", 2) ) for (j in 1:2) { reference <- suppressMessages(diptest::dip.test(features[, j])) expect_equal( observed$DipStatistic[[j]], unname(reference$statistic), tolerance = 2e-15 ) expect_equal( observed$DipPValue[[j]], reference$p.value, tolerance = 2e-14 ) } }) test_that("distance-analysis helper batches candidates above 72000", { set.seed(914) features <- cbind( A = rnorm(72001), B = c(rnorm(36000, -1), rnorm(36001, 1)) ) observed <- BIDistances:::.distance_distribution_analysis_dip_tests( features, 1:2 ) reference <- fast_dip_test_matrix( features, columns = 1:2, p.value.method = "asymptotic" ) expect_identical( observed$DipMethod, rep("fast_dip_test_matrix_asymptotic", 2) ) expect_equal( observed$DipStatistic, reference$DipStatistic, tolerance = 0 ) expect_equal( observed$DipPValue, reference$DipPValue, tolerance = 0 ) }) test_that("DistanceDistributionAnalysis reports DipStatistic", { skip_if_not_installed("DataVisualizations") skip_if_not_installed("diptest") skip_if_not_installed("e1071") set.seed(915) # 102 objects have 102 * 101 / 2 = 5151 upper-triangle pairs. pair_count <- 102 * 101 / 2 features <- cbind( Uniform = runif(pair_count), HalfNormal = abs(rnorm(pair_count)) ) invisible(capture.output( result <- DistanceDistributionAnalysis(features, PlotIt = FALSE) )) expect_true("DipStatistic" %in% names(result$SelectionStatistics)) for (j in seq_len(ncol(features))) { row <- match( colnames(features)[[j]], result$SelectionStatistics$Distance ) reference <- suppressMessages(diptest::dip.test(features[, j])) expect_equal( result$SelectionStatistics$DipStatistic[[row]], unname(reference$statistic), tolerance = 2e-15 ) expect_equal( result$SelectionStatistics$DipPValue[[row]], reference$p.value, tolerance = 2e-14 ) } })