tests/testthat/test-calc_purchasing_power.R

test_that("purchasing power with non-negative real interest rates", {
  
  calc_purchasing_power(x = 1, years = 1, real_interest_rate = 0) |> 
    expect_equal(1)
  
  calc_purchasing_power(x = 1, years = 50, real_interest_rate = 0.02) |> 
    round(1) |> 
    expect_equal(2.7)
})

test_that("purchasing power with negative real interest rates", {

  calc_purchasing_power(x = 10, years = 30, real_interest_rate = -0.02) |> 
    round(1) |> 
    expect_equal(5.5)
})

Try the R4GoodPersonalFinances package in your browser

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

R4GoodPersonalFinances documentation built on April 4, 2025, 1:48 a.m.