tests/testthat/test_ReferenceMeasureSeed.R

# The seed argument of ReferenceMeasureUniform() must (i) make construction
# reproducible on its own, (ii) match seeding the global RNG immediately
# before the call. The third condition
# "(iii) leave the global RNG state untouched, so that
# results of surrounding code do not depend on whether a reference measure
# is constructed in between."
# contradicts basic CRAN policies, and has been switched off for later
# development.

test_that("ReferenceMeasureUniform(seed=) is reproducible", {
  r1 <- ReferenceMeasureUniform(0, 1, sample=runif(100,0,1), seed = 42)
  r2 <- ReferenceMeasureUniform(0, 1, sample=runif(100,0,1), seed = 42)
  expect_identical(r1$sample, r2$sample)

  set.seed(42)
  s <- runif(100, 0, 1)
  expect_identical(r1$sample, s)
})

test_that("plot(..., type = 'scores') accepts a pch vector", {
  set.seed(7)
  x <- BDataSplines(matrix(rnorm(30 * 5, sd = 0.3), nrow = 30),
                    basis = B2Unif01Basis5)
  p <- suppressMessages(princomp(x))
  grDevices::pdf(NULL)
  on.exit(grDevices::dev.off())
  expect_no_error(plot(p, type = "scores", pch = rep(c(1, 2), 15)))
})

testthat::skip()
test_that("ReferenceMeasureUniform(seed=) restores the global RNG state", {
  set.seed(99)
  before <- .Random.seed
  invisible(ReferenceMeasureUniform(0, 1, sample=runif(50,0,1), seed = 1))
  expect_identical(.Random.seed, before)
  set.seed(99)
  x1 <- runif(3)
  set.seed(99)
  invisible(ReferenceMeasureUniform(0, 1, sample=runif(50,0,1), seed = 1))
  x2 <- runif(3)
  expect_identical(x1, x2)
})

Try the DistributionalDDA package in your browser

Any scripts or data that you put into this service are public.

DistributionalDDA documentation built on Oct. 20, 2026, 5:06 p.m.