-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
1e21e05
commit 8302c97
Showing
4 changed files
with
46 additions
and
55 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
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 |
---|---|---|
@@ -1,81 +1,81 @@ | ||
test_that("seek_variables - simple use case", { | ||
test_that("data_seek - simple use case", { | ||
data(iris) | ||
out <- seek_variables(iris, "Length") | ||
out <- data_seek(iris, "Length") | ||
expect_identical(out$index, c(1L, 3L)) | ||
expect_identical(out$labels, c("Sepal.Length", "Petal.Length")) | ||
}) | ||
|
||
test_that("seek_variables - seek label attribute", { | ||
test_that("data_seek - seek label attribute", { | ||
data(efc) | ||
out <- seek_variables(efc, "dependency") | ||
out <- data_seek(efc, "dependency") | ||
expect_identical(out$index, which(colnames(efc) == out$column)) | ||
expect_identical(out$labels, "elder's dependency") | ||
}) | ||
|
||
test_that("seek_variables - seek label attribute", { | ||
test_that("data_seek - seek label attribute", { | ||
data(efc) | ||
out <- seek_variables(efc, "female") | ||
out <- data_seek(efc, "female") | ||
expect_identical(nrow(out), 0L) | ||
out <- seek_variables(efc, "female", seek = "all") | ||
out <- data_seek(efc, "female", seek = "all") | ||
expect_identical(out$index, which(colnames(efc) == out$column)) | ||
expect_identical(out$labels, "elder's gender") | ||
}) | ||
|
||
test_that("seek_variables - fuzzy match", { | ||
test_that("data_seek - fuzzy match", { | ||
data(iris) | ||
out <- seek_variables(iris, "Lenght") | ||
out <- data_seek(iris, "Lenght") | ||
expect_identical(nrow(out), 0L) | ||
out <- seek_variables(iris, "Lenght", fuzzy = TRUE) | ||
out <- data_seek(iris, "Lenght", fuzzy = TRUE) | ||
expect_identical(out$index, which(colnames(iris) %in% out$column)) | ||
expect_identical(out$labels, c("Sepal.Length", "Petal.Length")) | ||
}) | ||
|
||
test_that("seek_variables - fuzzy match, value labels", { | ||
test_that("data_seek - fuzzy match, value labels", { | ||
data(efc) | ||
out <- seek_variables(efc, "femlae", seek = "all", fuzzy = TRUE) | ||
out <- data_seek(efc, "femlae", seek = "all", fuzzy = TRUE) | ||
expect_identical(nrow(out), 1L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, "elder's gender") | ||
}) | ||
|
||
test_that("seek_variables - multiple pattern", { | ||
test_that("data_seek - multiple pattern", { | ||
data(efc) | ||
out <- seek_variables(efc, c("e16", "e42")) | ||
out <- data_seek(efc, c("e16", "e42")) | ||
expect_identical(nrow(out), 2L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, c("elder's gender", "elder's dependency")) | ||
# only one match, typo | ||
out <- seek_variables(efc, c("femlae", "dependency")) | ||
out <- data_seek(efc, c("femlae", "dependency")) | ||
expect_identical(nrow(out), 1L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, "elder's dependency") | ||
# only one match, not searching in value labels | ||
out <- seek_variables(efc, c("female", "dependency")) | ||
out <- data_seek(efc, c("female", "dependency")) | ||
expect_identical(nrow(out), 1L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, "elder's dependency") | ||
# two matches | ||
out <- seek_variables(efc, c("female", "dependency"), seek = "all") | ||
out <- data_seek(efc, c("female", "dependency"), seek = "all") | ||
expect_identical(nrow(out), 2L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, c("elder's gender", "elder's dependency")) | ||
# only one match, typo | ||
out <- seek_variables(efc, c("femlae", "dependency"), seek = "all") | ||
out <- data_seek(efc, c("femlae", "dependency"), seek = "all") | ||
expect_identical(nrow(out), 1L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, "elder's dependency") | ||
# two matches, despite typo | ||
out <- seek_variables(efc, c("femlae", "dependency"), seek = "all", fuzzy = TRUE) | ||
out <- data_seek(efc, c("femlae", "dependency"), seek = "all", fuzzy = TRUE) | ||
expect_identical(nrow(out), 2L) | ||
expect_identical(out$index, which(colnames(efc) %in% out$column)) | ||
expect_identical(out$labels, c("elder's gender", "elder's dependency")) | ||
}) | ||
|
||
test_that("seek_variables - valid input", { | ||
expect_error(seek_variables(rnorm(10), "Length"), regex = "`data` must be a data frame.") | ||
expect_error(seek_variables(iris, "Length", seek = "somewhere"), regex = "`seek` must be") | ||
test_that("data_seek - valid input", { | ||
expect_error(data_seek(rnorm(10), "Length"), regex = "`data` must be a data frame.") | ||
expect_error(data_seek(iris, "Length", seek = "somewhere"), regex = "`seek` must be") | ||
}) | ||
|
||
test_that("seek_variables - print", { | ||
expect_snapshot(seek_variables(iris, "Length")) | ||
test_that("data_seek - print", { | ||
expect_snapshot(data_seek(iris, "Length")) | ||
}) |