From a18bdbd6b9eaa6da71e19729ee8ed4e8f1264f7e Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 12 Sep 2023 14:00:39 +0200 Subject: [PATCH] tests --- _pkgdown.yaml | 1 + tests/testthat/test-seek_data.R | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/testthat/test-seek_data.R diff --git a/_pkgdown.yaml b/_pkgdown.yaml index db2ebfeae..3a978e79f 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -63,6 +63,7 @@ reference: - data_codebook - data_tabulate - data_peek + - seek_variables - means_by_group - contains("distribution") - kurtosis diff --git a/tests/testthat/test-seek_data.R b/tests/testthat/test-seek_data.R new file mode 100644 index 000000000..45d7bdc35 --- /dev/null +++ b/tests/testthat/test-seek_data.R @@ -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") +})