# tests/testthat/test-eq5dmap.R In fragla/eq5d: Methods for Analysing 'EQ-5D' Data and Calculating 'EQ-5D' Index Scores

```context("EQ-5D version mapping")

test_that("EQ-5D-5L to EQ-5D-3L age/sex mapping by dimensions gives correct answer", {
expect_equal(eq5dmap(c(MO=1,SC=2,UA=3,PD=4,AD=5), "UK", "5L", 30, "female"), 0.067)
expect_equal(eq5dmap(c(MO=2,SC=4,UA=1,PD=1,AD=2), "UK", "5L", 50, "female"), 0.761)
expect_equal(eq5dmap(c(MO=2,SC=3,UA=4,PD=2,AD=1), "UK", "5L", 5, "male"), 0.609)
expect_equal(eq5dmap(c(MO=2,SC=3,UA=4,PD=2,AD=1), "UK", "5L", 5, "male", digits = 8), 0.60885463)
})

test_that("EQ-5D-3L to EQ-5D-5L age/sex mapping by dimensions gives correct answer", {
expect_equal(eq5dmap(c(MO=1,SC=2,UA=3,PD=2,AD=1), "UK", "3L", 30, "female"), 0.612)
expect_equal(eq5dmap(c(MO=2,SC=2,UA=1,PD=1,AD=2), "UK", "3L", 50, "female"), 0.712)
expect_equal(eq5dmap(c(MO=3,SC=3,UA=3,PD=3,AD=3), "UK", "3L", 3, "male"), -0.215)
expect_equal(eq5dmap(c(MO=3,SC=3,UA=3,PD=3,AD=3), "UK", "3L", 3, "male", digits = 8), -0.21529993)
})

test_that("EQ-5D-5L to EQ-5D-3L age/sex mapping by exact index gives correct answer", {
expect_equal(eq5dmap(0.922, "UK", "5L", 18, "male"), 0.893)
expect_equal(eq5dmap(0.922, "UK", "5L", 18, "male", digits = 8), 0.89307115)
})

test_that("EQ-5D-3L to EQ-5D-5L age/sex mapping by exact index gives correct answer", {
expect_equal(eq5dmap(-0.594, "UK", "3L", 95, "female"), -0.209)
expect_equal(eq5dmap(-0.594, "UK", "3L", 95, "female", digits = 8), -0.20907130)
})

test_that("EQ-5D-5L to EQ-5D-3L age/sex mapping by summary index gives correct answer", {
expect_equal(eq5dmap(0.715, "UK", "5L", 50, "male", bwidth = 0.0001), 0.670)
expect_equal(eq5dmap(0.435, "UK", "5L", 30, "female", bwidth = 0.0001), 0.302)
expect_equal(eq5dmap(0.95, "UK", "5L", 70, "male", bwidth = 0.0001), 0.935)
expect_equal(eq5dmap(0.715, "UK", "5L", 50, "male", bwidth = 0.1), 0.637)
expect_equal(eq5dmap(0.435, "UK", "5L", 30, "female", bwidth = 0.1), 0.297)
expect_equal(eq5dmap(0.95, "UK", "5L", 70, "male", bwidth = 0.1), 0.844)
})

test_that("EQ-5D-3L to EQ-5D-5L age/sex mapping by summary index gives correct answer", {
expect_equal(eq5dmap(-0.002, "UK", "3L", 50, "male", bwidth = 0.0001), NaN)
expect_equal(eq5dmap(0.234, "UK", "3L", 30, "female", bwidth = 0.0001), NaN)
expect_equal(eq5dmap(0.100, "UK", "3L", 70, "male", bwidth = 0.0001), 0.510)
expect_equal(eq5dmap(-0.002, "UK", "3L", 50, "male", bwidth = 0.1), 0.312)
expect_equal(eq5dmap(0.234, "UK", "3L", 30, "female", bwidth = 0.1), 0.579)
expect_equal(eq5dmap(0.100, "UK", "3L", 70, "male", bwidth = 0.1), 0.404)
})

context("eq5dmap Incorrect params")

test_that("eq5dmap throws error for incorrect parameters", {