tests/testthat/test_plotting_functions.R

test_that("Plotting function for non censored data do not produce errors", {
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  data(acidity)
  outttest <- MixNRMI1(acidity, Nit = 5, extras = TRUE)
  p <- plotCDF_noncensored(outttest)
  expect_output(str(p), "List of 9")
  p <- plotPDF_noncensored(outttest)
  expect_output(str(p), "List of 9")
  p <- qq_plot_noncensored(outttest)
  expect_output(str(p), "List of 9")
  p <- GOFplots(outttest)
  expect_output(str(p), "gtable")

  outttest2 <- MixNRMI2(acidity, Nit = 5, extras = TRUE)
  p <- plotCDF_noncensored(outttest2)
  expect_output(str(p), "List of 9")
  p <- plotPDF_noncensored(outttest2)
  expect_output(str(p), "List of 9")
  p <- qq_plot_noncensored(outttest2)
  expect_output(str(p), "List of 9")
  p <- GOFplots(outttest2)
  expect_output(str(p), "gtable")

  data(enzyme)
  outttest3 <- MixNRMI2(enzyme,
    Alpha = 1, Kappa = 0.007, Gama = 0.5,
    distr.k = 2, distr.py0 = 2,
    distr.pz0 = 2, mu.pz0 = 1, sigma.pz0 = 1, Meps = 0.005,
    Nit = 50, Pbi = 0.2, extras = TRUE
  )
  p <- plotCDF_noncensored(outttest3)
  expect_output(str(p), "List of 9")
  p <- plotPDF_noncensored(outttest3)
  expect_output(str(p), "List of 9")
  p <- GOFplots(outttest3)
  expect_output(str(p), "gtable")
  dev.off()
})

test_that("Plotting function for censored data do not produce errors", {
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  data(salinity)
  outttest <- MixNRMI1cens(salinity$left, salinity$right, Nit = 5, extras = TRUE)
  p <- plotCDF_censored(outttest)
  expect_output(str(p), "List of 9")
  p <- plotPDF_censored(outttest)
  expect_output(str(p), "List of 9")
  p <- qq_plot_censored(outttest)
  expect_output(str(p), "List of 9")
  p <- GOFplots(outttest)
  expect_output(str(p), "gtable")
  dev.off()
})

test_that("The traceplot function works", {
  data(salinity)
  fit <- multMixNRMI2cens(salinity$left, salinity$right, parallel = TRUE, Nit = 20, ncores = 2)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- BNPdensity:::traceplot(fit)
  expect_output(str(p), "gg")
  dev.off()
})


test_that("The plot methods works", {
  data(acidity)
  out <- MixNRMI1(acidity, Nit = 50)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- plot(out)
  expect_output(str(p), "gg")
  dev.off()
  data(acidity)
  out <- MixNRMI2(acidity, Nit = 50)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- plot(out)
  expect_output(str(p), "gg")
  dev.off()
  data(salinity)
  out <- MixNRMI1cens(salinity$left, salinity$right, Nit = 50)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- plot(out)
  expect_output(str(p), "gg")
  dev.off()
  data(salinity)
  out <- MixNRMI2cens(salinity$left, salinity$right, Nit = 50)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- plot(out)
  expect_output(str(p), "gg")
  dev.off()
  data(salinity)
  out <- multMixNRMI2cens(salinity$left, salinity$right, parallel = TRUE, Nit = 20, ncores = 2)
  pdf(file = tempfile(pattern = "file", tmpdir = tempdir(), fileext = ""))
  p <- plot(out)
  expect_output(str(p), "gg")
  dev.off()
})
konkam/BNPdensity documentation built on March 14, 2024, 7:15 a.m.