Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 12, 2023
1 parent dab2f53 commit a18bdbd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ reference:
- data_codebook
- data_tabulate
- data_peek
- seek_variables
- means_by_group
- contains("distribution")
- kurtosis
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/test-seek_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
test_that("seek_variables - simple use case", {
data(iris)
out <- seek_variables(iris, "Length")
expect_identical(out$index, c(1L, 3L))
expect_identical(out$labels, c("Sepal.Length", "Petal.Length"))
})

test_that("seek_variables - search label attribute", {
data(efc)
out <- seek_variables(efc, "dependency")
expect_identical(out$index, which(colnames(efc) == out$column))
expect_identical(out$labels, "elder's dependency")
})

test_that("seek_variables - search label attribute", {
data(efc)
out <- seek_variables(efc, "female")
expect_identical(nrow(out), 0L)
out <- seek_variables(efc, "female", source = "all")
expect_identical(out$index, which(colnames(efc) == out$column))
expect_identical(out$labels, "elder's gender")
})

test_that("seek_variables - fuzzy match", {
data(iris)
out <- seek_variables(iris, "Lenght")
expect_identical(nrow(out), 0L)
out <- seek_variables(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", {
data(efc)
out <- seek_variables(efc, "femlae", source = "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")
})

0 comments on commit a18bdbd

Please sign in to comment.