Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Add tests ref #35
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Nov 20, 2023
1 parent 3fdd505 commit 767b580
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/testthat/test-docvars.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ test_that("meta retention", {
expect_equal(test_corpus %>% tokens() %>% dfm() %>% meta("what"), "test")
expect_equal(test_corpus %>% tokens() %>% tokens_proximity(pattern = "world") %>% dfm() %>% meta("what"), "test")
})

test_that("docvars and meta methods", {
suppressPackageStartupMessages(library(quanteda))
test <- c("hello world!")
expect_equal(tokens(test) %>% tokens_proximity("world") %>% docvars() %>% colnames(), "proximity")
expect_error(tokens(test) %>% tokens_proximity("world") %>% meta(), NA)
})
9 changes: 9 additions & 0 deletions tests/testthat/test-tokens_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ test_that("Changing keywords", {
expect_error(res2 <- tokens_proximity(res, "life"), NA)
expect_equal(meta(res2, "keywords"), "life")
})

test_that("token_proximity() only emit token_proximity #35", {
suppressPackageStartupMessages(library(quanteda))
"this is my life" %>% tokens() %>% tokens_proximity("my") -> res
expect_equal(class(res), "tokens_with_proximity") # no tokens
expect_error(tokens_select(res, "life"))
expect_error(tokens_select(as.tokens(res), "life"), NA)
})

0 comments on commit 767b580

Please sign in to comment.