| Marc Kupietz | f632fe3 | 2026-09-08 07:58:46 +0200 | [diff] [blame] | 1 | test_that("vcLabels prefers the names a vector was given", { |
| 2 | vcLabels <- RKorAPClient:::vcLabels |
| 3 | |
| 4 | expect_equal( |
| 5 | vcLabels(c(before = "pubDate until 2009", since = "pubDate since 2010")), |
| 6 | c("before", "since") |
| 7 | ) |
| 8 | # nothing to prefer, so nothing is invented |
| 9 | expect_null(vcLabels(c("pubDate until 2009", "pubDate since 2010"))) |
| 10 | # a partly named vector is filled in from the definitions |
| 11 | expect_equal( |
| 12 | vcLabels(c(before = "pubDate until 2009", "pubDate since 2010")), |
| 13 | c("before", "since 2010") |
| 14 | ) |
| 15 | }) |
| 16 | |
| 17 | test_that("vcLabelsOrGuess always gives a label", { |
| 18 | expect_equal( |
| 19 | RKorAPClient:::vcLabelsOrGuess(c("pubDate until 2009", "pubDate since 2010")), |
| 20 | RKorAPClient:::queryStringToLabel(c("pubDate until 2009", "pubDate since 2010")) |
| 21 | ) |
| 22 | }) |
| 23 | |
| 24 | test_that("the query functions label virtual corpora by their names", { |
| 25 | skip_if_offline() |
| 26 | kco <- KorAPConnection(accessToken = NULL, verbose = FALSE) |
| 27 | vcs <- c(before = "pubDate until 2009", since = "pubDate since 2010") |
| 28 | |
| 29 | expect_equal(frequencyQuery(kco, "Ameisenplage", vcs)$label, c("before", "since")) |
| 30 | expect_equal(corpusStats(kco, vc = vcs, as.df = TRUE)$label, c("before", "since")) |
| 31 | expect_equal( |
| 32 | collocationScoreQuery(kco, "Grund", "triftiger", vc = vcs)$label, |
| 33 | c("before", "since") |
| 34 | ) |
| 35 | }) |
| 36 | |
| 37 | test_that("an unnamed vector leaves the result as it was", { |
| 38 | skip_if_offline() |
| 39 | kco <- KorAPConnection(accessToken = NULL, verbose = FALSE) |
| 40 | vcs <- c("pubDate until 2009", "pubDate since 2010") |
| 41 | |
| 42 | # no column appears where there is nothing to put in it |
| 43 | expect_false("label" %in% names(frequencyQuery(kco, "Ameisenplage", vcs))) |
| 44 | expect_false("label" %in% names(corpusStats(kco, vc = vcs, as.df = TRUE))) |
| 45 | # collocationScoreQuery has always labelled, and keeps deriving one |
| 46 | expect_equal( |
| 47 | collocationScoreQuery(kco, "Grund", "triftiger", vc = vcs)$label, |
| 48 | RKorAPClient:::queryStringToLabel(vcs) |
| 49 | ) |
| 50 | }) |
| 51 | |
| 52 | test_that("corpusStats does not hide the labels in row names", { |
| 53 | skip_if_offline() |
| 54 | kco <- KorAPConnection(accessToken = NULL, verbose = FALSE) |
| 55 | stats <- corpusStats( |
| 56 | kco, |
| 57 | vc = c(before = "pubDate until 2009", since = "pubDate since 2010"), |
| 58 | as.df = TRUE |
| 59 | ) |
| 60 | # row names are lost by the first bind_rows(), a column is not |
| 61 | expect_equal(rownames(stats), c("1", "2")) |
| 62 | expect_true("label" %in% names(stats)) |
| 63 | }) |