tests/testthat/test_pv.R

test_that("pv provides proper messages and warnings", {
  expect_error(pv(FV = "1000", .09, n = 5))
  expect_error(pv(FV = list(1, 2, 3), .09, n = 5))
  expect_message(pv(FV = 1000, .36, n = 5))
})

test_that("pv has correct dimensions and output type", {
  expect_is(pv(FV = 1000, .09, n = 5), "numeric")
  expect_true(is.vector(pv(FV = c(1000, 2000), .09, n = 5)))
  expect_length(pv(FV = c(1000, 2000), .09, n = 5), 2)
})

test_that("pv computes correctly", {
  expect_equal(pv(FV = 1000, .09, n = 5), 649.93)
  expect_lt(pv(FV = 1000, .09, n = 5), 650)
  expect_gt(pv(FV = 1000, .09, n = 5), 649)
  expect_equal(pv(FV = c(10, 20), .09, n = 5), c(6.5, 13))
})
bradleyboehmke/myfirstpackage documentation built on Dec. 21, 2017, 8:04 a.m.