tests/testthat/BDataSamples.R

# common part of the calculations
set.seed(234723)
x = runif(100)
xbds = BDataSamples(list(x), basis = B2Unif01Basis5)

y = runif(200)
xybds = BDataSamples(list(x,y), basis = B2Unif01Basis5)



test_that("creator returns right outcomes", {
  expect_s3_class(xbds, "BDataUnivariateSamples")
  expect_s3_class(xbds, "BDataSamples")
  expect_s3_class(xbds, "BData")
})


test_that("selectors work as expected", {
  expect_equal(sort(xbds), sort(xybds[1]))
})


test_that("addFrequency works as expected", {
  z = runif(100)
  zbds = BDataSamples(list(z), basis = B2Unif01Basis5)
  xypz = addFrequency(xybds, zbds)
  expect_equal(sort(c(x,z)), sort(unclass(xypz[1][[1]])), tolerance = 1e-10)
  expect_equal(sort(c(y,z)), sort(unclass(xypz[2][[1]])), tolerance = 1e-10)
  yxbds =  BDataSamples(list(y,x), basis = B2Unif01Basis5)
  xxyy = addFrequency(xybds, yxbds)
  expect_equal(sort(xxyy[1][[1]]), sort(xxyy[2][[1]]), tolerance = 1e-10)
})



test_that("internal accessory functions work as expected", {
  expect_equal(getBayesSpace(xybds), B2Unif01)
  expect_equal(getBayesSpaceBasis(xybds), B2Unif01Basis5)
})



test_that("interoperability with BDataFrequencyHistograms works as expected", {
  z = runif(500)
  zh = hist(z, plot = FALSE)
  xh = hist(x, plot = FALSE)
  zbdh = as.BDataFrequencyHistograms(list(z), basis = B2Unif01Basis20)
  xypz = addFrequency(zbdh, xybds)
  expect_equal(c(xypz[1]), zh$counts + xh$counts)
  expect_equal(getBayesSpaceBasis(xypz), getBayesSpaceBasis(zbdh))
  expect_equal(getBayesSpaceBasis(addFrequency(xybds,zbdh)), getBayesSpaceBasis(xybds))
})

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.