Skip to content

Commit

Permalink
Append testthat prefix for join_keys tests (#264)
Browse files Browse the repository at this point in the history
🥇

---------

Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 23, 2024
1 parent cab0e41 commit dd1c67c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Collate:
'cdisc_data.R'
'data.R'
Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-cdisc_join_keys.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
test_that("default_cdisc_join_keys is assigned in package environment", {
expect_true(exists("default_cdisc_join_keys"))
expect_gt(length(default_cdisc_join_keys), 0)
testthat::test_that("default_cdisc_join_keys is assigned in package environment", {
testthat::expect_true(exists("default_cdisc_join_keys"))
testthat::expect_gt(length(default_cdisc_join_keys), 0)
})

test_that("default_cdisc_join_keys subsetting of datasets with parent is valid", {
testthat::test_that("default_cdisc_join_keys subsetting of datasets with parent is valid", {
# indirect test to build_cdisc_join_keys
ds <- c("ADTTE", "ADSL")
result <- default_cdisc_join_keys[ds]
expect_length(result, 2)
expect_length(parents(result), 1)
testthat::expect_length(result, 2)
testthat::expect_length(parents(result), 1)
})

test_that("default_cdisc_join_keys subsetting of dataset without parent contains parent", {
testthat::test_that("default_cdisc_join_keys subsetting of dataset without parent contains parent", {
# indirect test to build_cdisc_join_keys
ds <- c("ADTTE", "ADEX", "ADRS")
result <- default_cdisc_join_keys[ds]
expect_length(result, 4)
expect_length(parents(result), 3)
testthat::expect_length(result, 4)
testthat::expect_length(parents(result), 3)
})
78 changes: 39 additions & 39 deletions tests/testthat/test-join_key.R
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
test_that("join_key throws error with NULL keys", {
expect_error(join_key("d1", "d2", keys = NULL))
testthat::test_that("join_key throws error with NULL keys", {
testthat::expect_error(join_key("d1", "d2", keys = NULL))
})

test_that("join_key throws error with NA keys", {
expect_error(join_key("d1", "d2", keys = NA))
expect_error(join_key("d1", "d2", keys = c("X" = "A", "B", NA)))
testthat::test_that("join_key throws error with NA keys", {
testthat::expect_error(join_key("d1", "d2", keys = NA))
testthat::expect_error(join_key("d1", "d2", keys = c("X" = "A", "B", NA)))
})

test_that("join_key throws error with numeric keys", {
expect_error(join_key("d1", "d2", keys = 1:10))
testthat::test_that("join_key throws error with numeric keys", {
testthat::expect_error(join_key("d1", "d2", keys = 1:10))
})

test_that("join_key throws error with data keys", {
expect_error(join_key("d1", "d2", keys = Sys.time() + seq(1, 5)))
testthat::test_that("join_key throws error with data keys", {
testthat::expect_error(join_key("d1", "d2", keys = Sys.time() + seq(1, 5)))
})

test_that("join_key throws error with invalid duplicate names in keys/values", {
expect_error(join_key("d1", "d2", keys = c("A" = "A", "A" = "B")))
expect_error(join_key("d1", "d2", keys = c("C" = "A", "D" = "A")))
testthat::test_that("join_key throws error with invalid duplicate names in keys/values", {
testthat::expect_error(join_key("d1", "d2", keys = c("A" = "A", "A" = "B")))
testthat::expect_error(join_key("d1", "d2", keys = c("C" = "A", "D" = "A")))
})

test_that("join_key throws error with invalid primary keys (names != keys)", {
expect_error(join_key("d1", "d1", keys = c("B" = "A", "A" = "B")))
expect_error(join_key("d1", keys = c("B" = "A", "A" = "B")))
testthat::test_that("join_key throws error with invalid primary keys (names != keys)", {
testthat::expect_error(join_key("d1", "d1", keys = c("B" = "A", "A" = "B")))
testthat::expect_error(join_key("d1", keys = c("B" = "A", "A" = "B")))
})

test_that("join_key throws error with invalid dataset arguments", {
testthat::test_that("join_key throws error with invalid dataset arguments", {
# missing
expect_error(join_key("d1", as.character(NA), keys = c("A" = "B", "C" = "D")))
testthat::expect_error(join_key("d1", as.character(NA), keys = c("A" = "B", "C" = "D")))
# invalid type
expect_error(join_key("d1", 5, keys = c("A" = "B", "C" = "D")))
testthat::expect_error(join_key("d1", 5, keys = c("A" = "B", "C" = "D")))
# invalid length
expect_error(join_key("d1", c("d1", "d2"), keys = c("A" = "B", "C" = "D")))
testthat::expect_error(join_key("d1", c("d1", "d2"), keys = c("A" = "B", "C" = "D")))
})

test_that("join_key does not throw error with valid arguments", {
testthat::test_that("join_key does not throw error with valid arguments", {
# keys of length 0
expect_silent(join_key("d1", "d2", keys = character(0)))
testthat::expect_silent(join_key("d1", "d2", keys = character(0)))
# keys of length 1
expect_silent(join_key("d1", "d2", keys = c("A" = "B")))
testthat::expect_silent(join_key("d1", "d2", keys = c("A" = "B")))
# keys of length > 1
expect_silent(join_key("d1", "d2", keys = c("A" = "B", "C" = "D")))
testthat::expect_silent(join_key("d1", "d2", keys = c("A" = "B", "C" = "D")))
# dataset_1 and dataset_2 can be the same if keys match
expect_silent(join_key("d1", "d1", keys = c("A" = "A", "B" = "B")))
testthat::expect_silent(join_key("d1", "d1", keys = c("A" = "A", "B" = "B")))

expect_silent(join_key("d1", keys = c("A" = "A", "B" = "B")))
testthat::expect_silent(join_key("d1", keys = c("A" = "A", "B" = "B")))
})

test_that("join_key will fill empty names with value", {
testthat::test_that("join_key will fill empty names with value", {
# keys of length 0
jk <- join_key("d1", "d2", keys = c("A" = "B", "C"))
expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("A", "C")))
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("A", "C")))

jk <- join_key("d1", "d2", keys = c("B", "C"))
expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("B", "C")))
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("B", "C")))
})

test_that("join_key will fill empty values with name", {
testthat::test_that("join_key will fill empty values with name", {
# keys of length 0
jk <- join_key("d1", "d2", keys = c("A" = "B", "C" = ""))
expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("A", "C")))
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("A", "C")))

jk <- join_key("d1", "d2", keys = c("B", "C" = ""))
expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("B", "C")))
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B", "C"), c("B", "C")))
})

test_that("join_key ignores empty name/value on keys if it has other keys", {
expect_message(jk <- join_key("d1", "d2", keys = c("A" = "B", "")), "are ignored")
expect_identical(jk[[1]][[1]], stats::setNames(c("B"), c("A")))
testthat::test_that("join_key ignores empty name/value on keys if it has other keys", {
testthat::expect_message(jk <- join_key("d1", "d2", keys = c("A" = "B", "")), "are ignored")
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B"), c("A")))

expect_message(jk <- join_key("d1", "d2", keys = c("B", "")), "are ignored")
expect_identical(jk[[1]][[1]], stats::setNames(c("B"), c("B")))
testthat::expect_message(jk <- join_key("d1", "d2", keys = c("B", "")), "are ignored")
testthat::expect_identical(jk[[1]][[1]], stats::setNames(c("B"), c("B")))
})

test_that("join_key sets key as character(0) when keys are all all empty strings", {
testthat::test_that("join_key sets key as character(0) when keys are all all empty strings", {
# invalid types
jk <- join_key("d1", "d2", keys = c("", "", "", ""))
expect_length(jk[[1]][[1]], 0)
testthat::expect_length(jk[[1]][[1]], 0)

jk2 <- join_key("d1", "d2", keys = c(" ", " ", " ", " "))
expect_length(jk2[[1]][[1]], 0)
testthat::expect_length(jk2[[1]][[1]], 0)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-join_keys-c.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ testthat::test_that("c.join_keys merges existing parents are overwritten", {
testthat::test_that("c.join_keys throws error when merge produces acyclical graph", {
jk1 <- join_keys(join_key("d1", "d2", "a"))
jk2 <- join_keys(join_key("d2", "d1", "a"))
expect_error(c(jk1, jk2), "Cycle detected in a parent and child dataset graph")
testthat::expect_error(c(jk1, jk2), "Cycle detected in a parent and child dataset graph")
})
6 changes: 3 additions & 3 deletions tests/testthat/test-join_keys-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ testthat::test_that("[[<-.join_keys removes keys with NULL and applies symmetric
my_keys[["d1"]][["d2"]] <- NULL


expect_equal(
testthat::expect_equal(
my_keys,
join_keys(join_key("d2", "d3", "B"))
)
Expand All @@ -411,13 +411,13 @@ testthat::test_that("[[<-.join_keys with empty name is changed to the key value"
# set empty key name
jk <- join_keys()
jk[["d1"]][["d2"]] <- c("A" = "B", "C")
expect_equal(jk[["d1"]][["d2"]], stats::setNames(c("B", "C"), c("A", "C")))
testthat::expect_equal(jk[["d1"]][["d2"]], stats::setNames(c("B", "C"), c("A", "C")))
})

testthat::test_that("[[<-.join_keys with empty value is set to its name", {
jk <- join_keys()
jk[["d1"]][["d2"]] <- c("A" = "B", "C" = "")
expect_equal(jk[["d1"]][["d2"]], stats::setNames(c("B", "C"), c("A", "C")))
testthat::expect_equal(jk[["d1"]][["d2"]], stats::setNames(c("B", "C"), c("A", "C")))
})

testthat::test_that("[[<-.join_keys passing key unnamed 'empty' value is ignored", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-join_keys.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ testthat::test_that("join_keys is a collection of join_key, ie named list with n
})

testthat::test_that("join_keys cannot create acyclical graph", {
expect_error(
testthat::expect_error(
join_keys(
join_key("d1", "d2", "A"),
join_key("d2", "d1", "A")
Expand Down Expand Up @@ -150,13 +150,13 @@ testthat::test_that("join_keys<-.teal_data overwrites existing join_keys", {
testthat::test_that("join_keys()[]<-.join_keys with empty name is changed to the key value", {
jk <- join_keys()
join_keys(jk)[["d1"]][["d2"]] <- c("A" = "B", "C")
expect_equal(jk[["d1"]][["d2"]], c(A = "B", C = "C"))
testthat::expect_equal(jk[["d1"]][["d2"]], c(A = "B", C = "C"))
})

testthat::test_that("join_keys()[]<-.join_keys with named empty valued is changed to its name", {
jk <- join_keys()
join_keys(jk)[["d1"]][["d2"]] <- c(A = "B", C = "")
expect_equal(jk[["d1"]][["d2"]], c(A = "B", C = "C"))
testthat::expect_equal(jk[["d1"]][["d2"]], c(A = "B", C = "C"))
})

testthat::test_that("join_keys()[]<-.join_keys with empty value in a named vector are ignored ", {
Expand Down

0 comments on commit dd1c67c

Please sign in to comment.