tests/testthat/test-calculate_price_index.R

test_that("Test calculate_price_index", {
  # Bad input
  expect_error(
    calculate_price_index(
      method = "invalid",
      dataset = data_constraxion,
      period_variable = "period",
      dependent_variable = "price",
      continuous_variables = "floor_area",
      categorical_variables = "neighbourhood_code"
    ),
    "Invalid method: 'invalid'"
  )
  
  # Laspeyres
  expect_silent(
    calculate_price_index(
      method = "laspeyres",
      dataset = data_constraxion,
      period_variable = "period",
      dependent_variable = "price",
      continuous_variables = "floor_area",
      categorical_variables = "neighbourhood_code",
      reference_period = 2015,
      number_of_observations = TRUE,
      imputation = TRUE
    )
  )
  
  # Paasche
  expect_silent(
    calculate_price_index(
      method = "paasche",
      dataset = data_constraxion,
      period_variable = "period",
      dependent_variable = "price",
      continuous_variables = "floor_area",
      categorical_variables = "neighbourhood_code",
      reference_period = 2015,
      number_of_observations = TRUE,
      imputation = FALSE
    )
  )
  
  # Fisher
  expect_silent(
    calculate_price_index(
      method = "fisher",
      dataset = data_constraxion,
      period_variable = "period",
      dependent_variable = "price",
      continuous_variables = "floor_area",
      categorical_variables = "neighbourhood_code",
      reference_period = 2015,
      number_of_observations = TRUE
    )
  )
  
  # HMTS
  expect_silent(
    calculate_price_index(
      method = "hmts",
      dataset = data_constraxion,
      period_variable = "period",
      dependent_variable = "price",
      continuous_variables = "floor_area",
      categorical_variables = "neighbourhood_code",
      reference_period = 2015,
      number_of_observations = TRUE,
      periods_in_year = 4,
      production_since = NULL,
      number_preliminary_periods = 2,
      resting_points = FALSE
    )
  )
})

Try the cbsREPS package in your browser

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

cbsREPS documentation built on June 8, 2025, 9:38 p.m.