1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
test_that("data_seek - simple use case", {
data(iris)
out <- data_seek(iris, "Length")
expect_identical(out$index, c(1L, 3L))
expect_identical(out$labels, c("Sepal.Length", "Petal.Length"))
})
test_that("data_seek - seek label attribute", {
data(efc)
out <- data_seek(efc, "dependency")
expect_identical(out$index, which(colnames(efc) == out$column))
expect_identical(out$labels, "elder's dependency")
})
test_that("data_seek - seek label attribute", {
data(efc)
out <- data_seek(efc, "female")
expect_identical(nrow(out), 0L)
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("data_seek - fuzzy match", {
data(iris)
out <- data_seek(iris, "Lenght")
expect_identical(nrow(out), 0L)
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("data_seek - fuzzy match, value labels", {
data(efc)
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("data_seek - multiple pattern", {
data(efc)
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 <- 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 <- 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 <- 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 <- 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 <- 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("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("data_seek - print", {
expect_snapshot(data_seek(iris, "Length"))
expect_snapshot(data_seek(iris, "abc"))
})
|