tests/testthat/test-plot-bqs.R

test_that("plot.bqs supports solutions ranked by 1se", {
  set.seed(1)
  dat <- cbind(rnorm(20), rnorm(20))
  ms <- list(
    function(x) gmix(x, K = 2, init = "kmeans"),
    function(x) gmix(x, K = 3, init = "kmeans")
  )
  b <- suppressWarnings(
    bqs(dat, ms, B = 2, type = "smooth", rankby = "1se", ncores = 1)
  )

  path <- tempfile(fileext = ".pdf")
  grDevices::pdf(path)
  on.exit({
    grDevices::dev.off()
    unlink(path)
  }, add = TRUE)

  expect_no_error(plot(b))
})

test_that("plot.bqs rejects unavailable scores before entering graphics setup", {
  set.seed(1)
  dat <- cbind(rnorm(20), rnorm(20))
  ms <- list(function(x) gmix(x, K = 2, init = "kmeans"))
  b <- bqs(dat, ms, B = 0, type = "smooth", rankby = "mean", ncores = 1)

  expect_error(
    plot(b, score = "oob_smooth"),
    "Invalid or unavailable 'score'"
  )
})

Try the qcluster package in your browser

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

qcluster documentation built on June 5, 2026, 5:07 p.m.