tests/testthat/test-eqhpg.R

context("EQ-5D HPG")

pre <- read.csv("../testdata/pre.csv")$x
post <- read.csv("../testdata/post.csv")$x

pre.df <- read.csv("../testdata/pre_df.csv")
post.df <- read.csv("../testdata/post_df.csv")


res <- read.csv("../testdata/hpg_3l_uk_tto_no_problems_false.csv")

test_that("eqhpg five digit gives correct answer", {
  expect_equal(hpg(pre, post, country = "UK", version="3L", type="TTO", no.problems = F), res)
})

test_that("eqhpg data.frame gives correct answer", {
  expect_equal(hpg(pre.df, post.df, country = "UK", version="3L", type="TTO", no.problems = F), res)
})

test_that("eqhpg data.frame throws error", {
  expect_error(hpg(pre.df, post, country = "UK", version="3L", type="TTO", ignore.invalid = FALSE))
  expect_error(hpg(pre.df, post.df, country = "UK", version="3L", type="TTO", dimensions=c("M0","SC","UA","PD","AD")))
  expect_error(hpg(pre.df[-1,], post.df, country = "UK", version="3L", type="TTO", ignore.invalid=TRUE))
  expect_error(hpg(pre, post, country = "UK", type="TTO", no.problems = F))
})

test_that("eq5dhpg using version='Y' is deprecated", {
  rlang::local_options(lifecycle_verbosity = "error")
  expect_error(hpg(pre, post, country = "Brazil", version="Y", type="CW", no.problems = F))
})

test_that("eq5d using version='Y' still works", {
  rlang::local_options(lifecycle_verbosity = "quiet")
  expect_equal(as.character(hpg(pre, post, country = "Brazil", version="Y", type="CW", no.problems = F)[2,]), c(158, 60, "Improve"))
})

Try the eq5d package in your browser

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

eq5d documentation built on June 20, 2025, 1:09 a.m.