tests/testthat/test_tfidf.R

bag1 <- data.frame(
  "words" = c("this", "is", "a", "sample"),
  "counts" = c(1, 1, 2, 1),
  stringsAsFactors = FALSE
)

bag2 <- data.frame(
  "words" = c("this", "is", "another", "example"),
  "counts" = c(1, 1, 2, 3),
  stringsAsFactors = FALSE
)

ll <- list("1" = bag1, "2" = bag2)

tfidf <- bags_to_tfidf(ll)

test_that("test tfidf #1", {

  example <- log(1 + 3) * log(2 / 1)
  expect_equal(example, tfidf[tfidf$words == "example", 3])

  a <- log(1 + 2) * log(2 / 1)
  expect_equal(a, tfidf[tfidf$words == "a", 2])

})

Try the jmotif package in your browser

Any scripts or data that you put into this service are public.

jmotif documentation built on March 26, 2020, 7:23 p.m.