tests/testthat/test-nsim.R

context("nsim")

test_that("nsim returns a single, double value", {
  expect_length(
    nsim(alpha = 0.05, sigma = 1, delta = 1, power = 0.5),
    n = 1
  )
  expect_type(
    nsim(alpha = 0.05, sigma = 1, delta = 1, power = 0.5),
    type = "double"
  )
})

test_that("alpha is in the appropriate range", {
  expect_error(
    nsim(alpha = 1.5, sigma = 1, delta = 1, power = 0.5),
    "Variable 'alpha': .+ <= 1",
    fixed = FALSE
  )
  expect_error(
    nsim(alpha = -0.1, sigma = 1, delta = 1, power = 0.5),
    "Variable 'alpha': .+ >= 0",
    fixed = FALSE
  )
})

test_that("sigma is greater than zero", {
  expect_error(
    nsim(alpha = 0.05, sigma = -0.1, delta = 1, power = -0.1),
    "Variable 'sigma': .+ >= 0",
    fixed = FALSE
  )
})

test_that("delta is greater than zero", {
  expect_error(
    nsim(alpha = 0.05, sigma = 1, delta = -0.1, power = -0.1),
    "Variable 'delta': .+ >= 0",
    fixed = FALSE
  )
})

test_that("power is in the appropriate range", {
  expect_error(
    nsim(alpha = 0.05, sigma = 1, delta = 1, power = 1.5),
    "Variable 'power': .+ <= 1",
    fixed = FALSE
  )
  expect_error(
    nsim(alpha = 0.05, sigma = 1, delta = 1, power = -0.1),
    "Variable 'power': .+ >= 0",
    fixed = FALSE
  )
})

Try the rsimsum package in your browser

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

rsimsum documentation built on June 21, 2018, 5:04 p.m.