-
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.
- Loading branch information
Showing
2 changed files
with
78 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,88 @@ | ||
library(testthat) | ||
context("NIH Table") | ||
|
||
d1 <- tibble::tribble( | ||
~subject_id, ~gender, ~race, ~ethnicity, | ||
1L, "Male", "Black or African American", "Not Hispanic or Latino", | ||
2L, "Male", "Black or African American", "Not Hispanic or Latino", | ||
3L, "Female", "Black or African American", "Not Hispanic or Latino", | ||
4L, "Male", "White", "Not Hispanic or Latino", | ||
5L, "Male", "White", "Not Hispanic or Latino", | ||
6L, "Female", "White", "Not Hispanic or Latino", | ||
7L, "Male", "White", "Hispanic or Latino", | ||
8L, "Male", "White", "Hispanic or Latino" | ||
expected_1 <- structure( | ||
list(gender = c("Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Male", "Male", "Male", "Male", | ||
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", | ||
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", | ||
"Male", "Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported" | ||
), race = c("American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White"), ethnicity = c("Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity"), | ||
n = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, | ||
2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L)), class = c("tbl_df", "tbl", "data.frame" | ||
), row.names = c(NA, -63L) | ||
) | ||
|
||
|
||
ds_1a <- tibble::tribble( | ||
~subject_id, ~gender, ~race, ~ethnicity, | ||
1L, "Male", "Black or African American", "Not Hispanic or Latino", | ||
2L, "Male", "Black or African American", "Not Hispanic or Latino", | ||
3L, "Female", "Black or African American", "Not Hispanic or Latino", | ||
4L, "Male", "White", "Not Hispanic or Latino", | ||
5L, "Male", "White", "Not Hispanic or Latino", | ||
6L, "Female", "White", "Not Hispanic or Latino", | ||
7L, "Male", "White", "Hispanic or Latino", | ||
8L, "Male", "White", "Hispanic or Latino" | ||
) | ||
|
||
test_that("Smoke Test", { | ||
testthat::skip_on_cran() | ||
|
||
observed <- table_nih_enrollment(d1) | ||
test_that("Smoke Test", { | ||
observed <- table_nih_enrollment(ds_1a) | ||
expect_true(!is.null(observed)) | ||
}) | ||
|
||
test_that("d1", { | ||
testthat::skip_on_cran() | ||
expected <- structure( | ||
list(gender = c("Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Female", "Female", "Female", "Female", | ||
"Female", "Female", "Female", "Male", "Male", "Male", "Male", | ||
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", | ||
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male", | ||
"Male", "Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported", | ||
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported" | ||
), race = c("American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native", | ||
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American", | ||
"Black or African American", "Black or African American", "More than One Race", | ||
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander", | ||
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander", | ||
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported", | ||
"White", "White", "White"), ethnicity = c("Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino", | ||
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity"), | ||
n = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, | ||
2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, | ||
0L, 0L, 0L, 0L, 0L)), class = c("tbl_df", "tbl", "data.frame" | ||
), row.names = c(NA, -63L) | ||
) | ||
observed <- table_nih_enrollment(d1) # dput(observed) | ||
|
||
expect_equal(observed, expected) | ||
|
||
test_that("ds_1a", { | ||
observed <- table_nih_enrollment(ds_1a) # dput(observed) | ||
expect_equal(observed, expected_1) | ||
}) |