-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds tests and simplifies cdisc_data
- Loading branch information
1 parent
0521c89
commit 78996ec
Showing
9 changed files
with
160 additions
and
54 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
#' Generate a teal_data dataset with sample data and JoinKeys | ||
helper_generator_teal_data <- function() { | ||
iris2 <- iris | ||
iris2$id <- rnorm(NROW(iris2)) | ||
iris2$id <- apply(iris2, 1, rlang::hash) | ||
new_teal_data( | ||
list( | ||
ds1 = iris2, | ||
ds2 = iris2 | ||
), | ||
code = "ds1 <- iris2; ds2 <- iris2", | ||
keys = helper_generator_JoinKeys("ds1", keys = c("id")) | ||
) | ||
} | ||
|
||
#' Generate a JoinKeys | ||
helper_generator_JoinKeys <- function(dataset_1 = "ds1", keys = c("id")) { | ||
join_keys( | ||
join_key(dataset_1, keys = keys) | ||
) | ||
} | ||
|
||
#' Test suite for default get_join generated by helper | ||
helper_test_get_join_keys <- function(obj, dataset_1 = "ds1") { | ||
jk <- get_join_keys(obj) | ||
|
||
expect_s3_class(jk, c("JoinKey", "R6")) | ||
expect_length(jk$get(), 1) | ||
expect_length(jk$get(dataset_1), 1) | ||
|
||
obj | ||
} | ||
|
||
#' Test suite for JoinKeys after manual adding a primary key | ||
helper_test_get_join_keys_add <- function(obj, dataset_1 = "ds1", new_dataset_1 = "ds2", new_keys = c("id")) { | ||
obj <- helper_test_get_join_keys(obj, dataset_1) | ||
get_join_keys(obj)[new_dataset_1] <- c(new_keys) | ||
|
||
jk <- get_join_keys(obj) | ||
|
||
checkmate::expect_r6(jk, c("JoinKeys")) | ||
expect_length(jk$get(), 2) | ||
expect_length(jk$get(dataset_1), 1) | ||
expect_length(jk$get(new_dataset_1), 1) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
test_that("get_join_keys.teal_data will successfully obtain object from teal_data", { | ||
obj <- helper_generator_teal_data() | ||
|
||
expect_identical(obj@join_keys, get_join_keys(obj)) | ||
helper_test_get_join_keys(obj, "ds1") | ||
}) | ||
|
||
test_that("get_join_keys.JoinKeys will return itself", { | ||
obj <- helper_generator_JoinKeys() | ||
|
||
expect_identical(obj, get_join_keys(obj)) | ||
helper_test_get_join_keys(obj, "ds1") | ||
}) | ||
|
||
test_that("get_join_keys<-.teal_data", { | ||
obj <- helper_generator_teal_data() | ||
helper_test_get_join_keys_add(obj, "ds1", "ds2") | ||
}) | ||
|
||
test_that("get_join_keys<-.JoinKeys", { | ||
obj <- helper_generator_JoinKeys() | ||
helper_test_get_join_keys_add(obj, "ds1", "ds2") | ||
}) |