tests/testthat/test_check_init_chain.R

context("check_init_chain")

width.bad <- list(center = 10,
                  width = -10,
                  pmin = 0.2,
                  pmax = 0.8,
                  deltaL = 2,
                  tauL = 0.5,
                  deltaR = 3,
                  tauR = 0.5)
pmin.bad <- list(center = 10,
                  width = 10,
                  pmin = -0.2,
                  pmax = 0.8,
                  deltaL = 2,
                  tauL = 0.5,
                  deltaR = 3,
                  tauR = 0.5)
pmax.bad <- list(center = 10,
                 width = 10,
                 pmin = 0.2,
                 pmax = 1.1,
                 deltaL = 2,
                 tauL = 0.5,
                 deltaR = 3,
                 tauR = 0.5)
pmax.small <- list(center = 10,
                    width = 10,
                    pmin = 0.2,
                    pmax = 0.1,
                    deltaL = 2,
                    tauL = 0.5,
                    deltaR = 3,
                    tauR = 0.5)
deltaL.bad <- list(center = 10,
                   width = 10,
                   pmin = 0.2,
                   pmax = 0.3,
                   deltaL = -2,
                   tauL = 0.5,
                   deltaR = 3,
                   tauR = 0.5)
deltaR.bad <- list(center = 10,
                   width = 10,
                   pmin = 0.2,
                   pmax = 0.3,
                   deltaL = 2,
                   tauL = 0.5,
                   deltaR = -3,
                   tauR = 0.5)
deltaM.bad <- list(center = 10,
                   width = 10,
                   pmin = 0.2,
                   pmax = 0.3,
                   deltaM = -2,
                   tauM = 0.5)
tauL.bad <- list(center = 10,
                 width = 10,
                 pmin = 0.2,
                 pmax = 0.3,
                 deltaL = 2,
                 tauL = -0.5,
                 deltaR = 3,
                 tauR = 0.5)
tauR.bad <- list(center = 10,
                 width = 10,
                 pmin = 0.2,
                 pmax = 0.3,
                 deltaL = 2,
                 tauL = 0.5,
                 deltaR = 3,
                 tauR = 1.1)
tauM.bad <- list(center = 10,
                 width = 10,
                 pmin = 0.2,
                 pmax = 0.3,
                 deltaL = 2,
                 tauM = -0.5,
                 deltaR = 3,
                 tauR = 0.5)
good <- list(center = 10,
              width = 10,
              pmin = 0.2,
              pmax = 0.3,
              deltaL = 2,
              tauL = 0.5,
              deltaR = 3,
              tauR = 0.5,
              f = 0.5)

test_that("check_init_chain checks argument", {
  expect_error(check_init_chain(good, type = "xxx"), "should")
})

test_that("check_init_chain output is correct", {
  expect_equal(check_init_chain(width.bad, type = "geno"), "width")
  expect_equal(check_init_chain(pmin.bad, type = "geno"), "pmin")
  expect_equal(check_init_chain(pmax.bad, type = "geno"), "pmax")
  expect_equal(check_init_chain(pmax.small, type = "geno"), c("pmin", "pmax"))
  expect_null(check_init_chain(pmin.bad, type = "pheno"))
  expect_null(check_init_chain(pmax.bad, type = "pheno"))
  expect_equal(check_init_chain(pmax.small, type = "pheno"), c("pmin", "pmax"))
  expect_equal(check_init_chain(deltaL.bad, type = "geno"), "deltaL")
  expect_equal(check_init_chain(deltaR.bad, type = "geno"), "deltaR")
  expect_equal(check_init_chain(deltaM.bad, type = "geno"), "deltaM")
  expect_equal(check_init_chain(tauL.bad, type = "geno"), "tauL")
  expect_equal(check_init_chain(tauR.bad, type = "geno"), "tauR")
  expect_equal(check_init_chain(tauM.bad, type = "geno"), "tauM")
  expect_null(check_init_chain(good))
})
tjthurman/BAHZ documentation built on May 30, 2020, 8:28 a.m.