Skip to content

Commit 5306a40

Browse files
committed
Additional test for age_in_years parameter
1 parent 19b9e00 commit 5306a40

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/testthat/test-derive_anthro_scores.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,34 @@ test_that("rows with NA AGE are excluded (AGE_DAYS becomes NA and filter removes
8181
expect_true(is.na(out[which(out$USUBJID == "NA_age"), "WAZ_FLAG"]))
8282
})
8383

84+
test_that("convert_age_to_years works when age_in_years is FALSE", {
85+
df <- tibble::tibble(
86+
STUDYID = "S",
87+
USUBJID = c("A", "B"),
88+
SEX = c(1, 2),
89+
AGE = c(24, 104),
90+
AGEU = c("MONTHS", "WEEKS"),
91+
WEIGHT_kg = c(20, 30),
92+
HEIGHT_cm = c(110, 140)
93+
)
94+
95+
expect_error(derive_anthro_scores(df), "Required variable")
96+
97+
out <- derive_anthro_scores(df, age_in_years = FALSE)
98+
99+
expect_true(all(c("HAZ", "HAZ_FLAG", "WAZ", "WAZ_FLAG", "WHZ", "WHZ_FLAG") %in% colnames(out)))
100+
})
84101

102+
test_that("convert_age_to_years fails when age_in_years is FALSE but no AGE vars", {
103+
df <- tibble::tibble(
104+
STUDYID = "S",
105+
USUBJID = c("A", "B"),
106+
SEX = c(1, 2),
107+
WEIGHT_kg = c(20, 30),
108+
HEIGHT_cm = c(110, 140)
109+
)
110+
111+
expect_error(derive_anthro_scores(df, age_in_years = FALSE),
112+
"Required variable")
113+
114+
})

0 commit comments

Comments
 (0)