test_that("fast p-values agree with diptest across all calibrations", { skip_if_not_installed("diptest") set.seed(21985) sizes <- unique(c( BIDistances:::.fastdip_sample_sizes, 17, 63, 999, 72001 )) for (n in sizes) { x <- switch( as.character(n %% 3), "0" = rnorm(n), "1" = round(rnorm(n), 1), "2" = c(rnorm(n %/% 2, -1), rnorm(n - n %/% 2, 1)) ) got <- fast_dip_test(x) ref <- suppressMessages(diptest::dip.test(x)) got_statistic <- as.numeric(got$statistic) ref_statistic <- as.numeric(ref$statistic) statistic_error <- abs(got_statistic - ref_statistic) # Compare independent C++ and C implementations numerically, not bitwise. expect_true( statistic_error <= 1e-12, info = paste( "n =", n, "absolute statistic error =", format(statistic_error, digits = 17) ) ) expect_equal( got$p.value, ref$p.value, tolerance = 2e-14, info = paste("n =", n) ) expect_equal(got$nobs, ref$nobs, tolerance = 0) } }) test_that("calibration choices are explicit at the 72000 boundary", { set.seed(1) x <- rnorm(72000) at_limit <- fast_dip_test(x) expect_identical(at_limit$p.value.method, "table (last row)") x_large <- c(x, rnorm(1)) expect_warning( above <- fast_dip_test(x_large, warn.asymptotic = TRUE), "limiting calibration" ) expect_identical(above$p.value.method, "asymptotic") expect_error( fast_dip_test(x_large, p.value.method = "table"), "ends at n = 72000" ) }) test_that("bootstrap calibration is reproducible", { set.seed(7) x <- c(rnorm(50, -1), rnorm(50, 1)) set.seed(2026) a <- fast_dip_test(x, p.value.method = "bootstrap", B = 50) set.seed(2026) b <- fast_dip_test(x, simulate.p.value = TRUE, B = 50) expect_equal(a$p.value, b$p.value, tolerance = 0) expect_identical(a$p.value.method, "bootstrap") })