# Tests for mhqol_scores_to_states function  ------------------------------
# Test whether when ignore_na = FAlSE, the function returns an Error when there are NA values in the data
test_that("Test whether when ignore_na = FAlSE, the function returns an Error when there are NA values in the data", {
expect_error(mhqol_scores_to_states(scores = data.frame(SI = c(3, 2, NA),
# Test whether when ignore_na = TRUE, the function does not return an Error but a Warning when there are NA values in the data
test_that("Test whether when ignore_na = TRUE, the function returns a warning when there are NA values in the data", {
expect_warning(mhqol_scores_to_states(scores = data.frame(SI = c(3, 2, NA),
# Test whether when ignore_invalid = FALSE, the function returns an Error when there are missing cols in the data
test_that("Test whether when ignore_invalid = FALSE, the function returns an Error when there are missing cols in the data", {
expect_error(mhqol_scores_to_states(scores = data.frame(SI = c(3,2,1),
FU = c(2,1,1)), ignore_invalid = FALSE))
# Test whether when ignore_invalid = TRUE, the function does not return an Error but a Warning when there are missing cols in the data
test_that("Test whether when ignore_invalid = TRUE, he function does not return an Error but a Warning when there are missing cols in the data", {
expect_warning(mhqol_scores_to_states(scores = data.frame(SI = c(3,2,1),
# Test whether when retain_old_variables = TRUE, the function also returns the original variables in the data
test_that("Test whether when retain_old_variables = TRUE, the function also returns the original variables in the data", {
df <- mhqol_scores_to_states(scores = data.frame(SI = c(3, 2, 1),
FU = c(2,1,1)), retain_old_variables = TRUE)
expect_true(all(c("SI", "IN", "MO", "RE", "DA", "PH", "FU") %in% colnames(df)))
# Test whether when retain_old_variables = FALSE, the function does not return the original variables in the data
test_that("Test whether when retain_old_variables = FALSE, the function does not return the original variables in the data", {
FU = c(2,1,1)), retain_old_variables = FALSE)
expect_false(all(c("SI", "IN", "MO", "RE", "DA", "PH", "FU") %in% colnames(df)))
# Test whether the function returns the correct scores for the states
test_that("Test whether the function returns the correct states for the scores", {
df <- mhqol_scores_to_states(scores = data.frame(SI = c(3,2,1,0),
expect_equal(df$SI_s, c("I think very positively about myself",
"I think very negatively about myself"))
expect_equal(df$IN_s, c("I am very satisfied with my level of independence",
"I am satisfied with my level of independence",
"I am dissatisfied with my level of independence",
"I am very dissatisfied with my level of independence"))
expect_equal(df$MO_s, c("I do not feel anxious, gloomy, or depressed",
"I feel a little anxious, gloomy, or depressed",
"I feel very anxious, gloomy, or depressed"))
expect_equal(df$RE_s, c("I am very satisfied with my relationships",
"I am dissatisfied with my relationships",
"I am very dissatisfied with my relationships"))
expect_equal(df$DA_s, c("I am very satisfied with my daily activities",
"I am satisfied with my daily activities",
"I am dissatisfied with my daily activities",
"I am very dissatisfied with my daily activities"))
expect_equal(df$PH_s, c("I have no physical health problems",
"I have a great many physical health problems"))
expect_equal(df$FU_s, c("I am very optimistic about my future",
# Test whether the function returns an error when there is a score below zero in the data
test_that("Test whether the function returns an error when there is a score below zero in the data", {
expect_error(mhqol_scores_to_states(scores = data.frame(SI = c(3,2,1,0),
# Test whether the function returns an error when there is a score above 3 in the data
test_that("Test whether the function returns an error when there is a score above 3 in the data", {