-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from OxfordIHTM/dev
add tests for recode sex and recode age type
- Loading branch information
Showing
9 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is part of the standard setup for testthat. | ||
# It is recommended that you do not modify it. | ||
# | ||
# Where should you do additional test configuration? | ||
# Learn more about the roles of various files in: | ||
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview | ||
# * https://testthat.r-lib.org/articles/special-files.html | ||
|
||
library(testthat) | ||
library(codeditr) | ||
|
||
test_check("codeditr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Tests for recode age type ---------------------------------------------------- | ||
|
||
age_type <- c(rep("D", 3), rep("M", 2), rep("Y", 3)) | ||
|
||
age_type1 <- c(rep("d", 3), rep("m", 2), rep("y", 3)) | ||
age_type_code1 <- c("d", "m", "y") | ||
|
||
age_type2 <- c(rep("days", 3), rep("months", 2), rep("years", 3)) | ||
age_type_code2 <- c("days", "months", "years") | ||
|
||
age_type3 <- c(rep(1L, 3), rep(2L, 2), rep(3L, 3)) | ||
age_type_code3 <- c(1L, 2L, 3L) | ||
|
||
age_type4 <- c(rep("d", 3), "m", NA_character_, rep("y", 3)) | ||
age_type_code4 <- c("d", "m", "y") | ||
|
||
age_type5 <- c(rep(1L, 3), 2L, NA_integer_, rep(3L, 3)) | ||
age_type_code5 <- c(1L, 2L, 3L) | ||
|
||
expected <- c(rep("D", 3), rep("M", 2), rep("Y", 3)) | ||
expected_na <- c(rep("D", 3), "M", NA_character_, rep("Y", 3)) | ||
|
||
|
||
testthat::test_that( | ||
"output of recode age type is as expected", { | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type), | ||
expected | ||
) | ||
|
||
## input is different characters ---- | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type1, age_type_code = age_type_code1), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type1, age_type_code = age_type_code1), | ||
expected | ||
) | ||
|
||
## input is different characters ---- | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type2, age_type_code = age_type_code2), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type2, age_type_code = age_type_code2), | ||
expected | ||
) | ||
|
||
## input is integer ---- | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type3, age_type_code = age_type_code3), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type3, age_type_code = age_type_code3), | ||
expected | ||
) | ||
|
||
## input has NA ---- | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type4, age_type_code = age_type_code4), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type4, age_type_code = age_type_code4), | ||
expected_na | ||
) | ||
|
||
## input has NA ---- | ||
expect_vector( | ||
cod_recode_age_type(age_type = age_type5, age_type_code = age_type_code5), | ||
ptype = character(), | ||
size = 8 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_age_type(age_type = age_type5, age_type_code = age_type_code5), | ||
expected_na | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Tests for recode sex --------------------------------------------------------- | ||
|
||
sex_value <- c(rep(1L, 2), rep(2L, 3), NA_integer_) | ||
|
||
sex_value1 <- c(rep("m", 2), rep("f", 3), NA_character_) | ||
sex_code1 <- c("m", "f") | ||
|
||
expected <- c(1L, 1L, 2L, 2L, 2L, NA_integer_) | ||
expected_codedit <- c(1L, 1L, 2L, 2L, 2L, 9L) | ||
|
||
testthat::test_that( | ||
"output of recode sex is as expected", { | ||
expect_vector( | ||
cod_recode_sex(sex_value = sex_value), ptype = integer(), size = 6 | ||
) | ||
|
||
expect_equal(cod_recode_sex(sex_value = sex_value), expected_codedit) | ||
|
||
expect_vector( | ||
cod_recode_sex( | ||
sex_value = sex_value1, sex_code = sex_code1, codedit = FALSE | ||
), | ||
ptype = integer(), | ||
size = 6 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_sex( | ||
sex_value = sex_value1, sex_code = sex_code1, codedit = FALSE | ||
), | ||
expected | ||
) | ||
|
||
expect_vector( | ||
cod_recode_sex(sex_value = sex_value1, sex_code = sex_code1), | ||
ptype = integer(), | ||
size = 6 | ||
) | ||
|
||
expect_equal( | ||
cod_recode_sex( | ||
sex_value = sex_value1, sex_code = sex_code1, codedit = TRUE | ||
), | ||
expected_codedit | ||
) | ||
} | ||
) |