Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage #221

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/testthat/test-assign-id.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ test_that("assign_id sets new ID's larger than the previous data even if no subj
expect_equal(nrow(ids_assigned), 3)
expect_equal(ncol(ids_assigned), 2)
expect_true(all(c(20, 21, 22) %in% unique(ids_assigned$ID)))

data2 <- dplyr::tibble(USUBJID2 = c("E", "F", "G"))
expect_error(assign_id(.data = data2, .subject_col = "USUBJID2", .previously_derived_path = lookup_path))
})

test_that("assign_id stops if data is grouped", {
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test-execute-data-diffs.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,36 @@ test_that("The function works if .suject_col is NULL", {
)

})

test_that("Test if data.frames don't have shared names", {
base_df <- data.frame(A = c(1, 2), B = c(4, 7), C = c(5, 9))
compare_df <- data.frame(D = c(1, 2), E = c(4, 7), F = c(5, 9))

expect_error(
execute_data_diffs(base_df, compare_df,
"The base and compare data frames do not have any columns to compare"))
})

# Create test data frames
.compare_df3 <- data.frame(
ID = c(1, 2, 3),
A = c("a", "b", "c"),
B = c(1, 2, 2.5)
)

.base_df3 <- data.frame(
ID = c(1, 2, 3, 4),
A = c("a", "b", "c", "d"),
B = c(1, 2, 3, 4),
C = c(4, 5, 6, 7)
)

test_that("execute_data_diffs works with removing columns", {
diffs_list3 <- execute_data_diffs(.base_df3, .compare_df3, "ID")

diffs <- diffs_list3$diffs
expect_equal(diffs$value[1], "1 row(s) removed")
expect_equal(diffs$name[2], "Removed Columns")
expect_equal(diffs$value[2], "C")
})

16 changes: 16 additions & 0 deletions tests/testthat/test-list-files-of-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ test_that("list_files_of_type: check xpt works in test dir", {
test_that("list_files_of_type: check sas7bdat does not work in test dir", {
expect_equal(length(list_files_of_type(path, "sas7bdat")$files_of_type), 0)
})

test_that("list_files_of_type returns message if file type not csv, xpt or sas7bdat", {
michaelmcd18 marked this conversation as resolved.
Show resolved Hide resolved

if (!dir.exists(file.path(tempdir(), "listfiletype"))) {
dir.create(file.path(tempdir(), "listfiletype"))
}

write_csv_dots(data.frame(A = c(1,2), B = c(3,4)), file = file.path(tempdir(), "listfiletype/example.csv"))
write_csv_dots(data.frame(A = c(1,2), B = c(3,4)), file = file.path(tempdir(), "listfiletype/example2.csv"))
haven::write_xpt(data.frame(A = c(1,2), B = c(3,4)), file.path(tempdir(), "listfiletype/example.xpt"))

file_type_df <- list_files_of_type(file.path(tempdir(), "listfiletype"), .file_types = "detect") %>% suppressMessages()
expect_true(file_type_df$type == "csv")
expect_true(length(file_type_df$files_of_type) == 2)

})
4 changes: 4 additions & 0 deletions tests/testthat/test-query-src-list.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ test_that("query_src_list returns all domain and column combinations with a matc
query_the <- query_src_list(.src_list = src_list, .string = "THE") %>% suppressMessages()
query_subject <- query_src_list(.src_list = src_list, .string = "CDISC01.200002") %>% suppressMessages()

expect_message(
query_src_list(.src_list = src_list, .string = "No matches zzz"),
"No matches found for No matches zzz")

expect_true(query_white$DOMAIN == "dm")
expect_true(query_white$COLUMNS == "RACE")

Expand Down