tests/testthat/test_financialfunctions.R

context("Financial functions")

test_that("Error handling", {
  expect_error(irr(c(1, 1)))
})

test_that("Matches Excel", {
  expect_equal(npv(0.05, values = c(4, 3, 2, 1)), 9.08098991675279)
  expect_equal(irr(c(-1, 1)), 0)
  expect_equal(round(pv(0.05, 3, 1), 2), -2.72)
  expect_equal(round(pmt(0.05, 3, 5), 2), -1.84)
  expect_equal(round(fv(0.05, 5, 2), 2), -11.05)
})

Try the grattan package in your browser

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

grattan documentation built on Sept. 4, 2023, 5:08 p.m.