tests/testthat/test-count.R

test_that("count works", {
  expect_identical(count(strsplit("strawberry", "")[[1]], "r"), 3L)
  expect_identical(count(chars("strawberry"), "r"), 3L)
  expect_identical(count(strsplit("strawberry", "")[[1]], "x"), 0L)
  expect_identical(count(chars("strawberry"), "x"), 0L)

  expect_identical(count(chars("StRaWbErRy"), "r", ignore.case = FALSE), 1L)
  expect_identical(count(chars("StRaWbErRy"), "R", ignore.case = FALSE), 2L)
  expect_identical(count(chars("StRaWbErRy"), "r", ignore.case = TRUE), 3L)
  expect_identical(count(chars("StRaWbErRy"), "R", ignore.case = TRUE), 3L)
  expect_identical(count(chars("StRaWbErRy"), "x", ignore.case = FALSE), 0L)
  expect_identical(count(chars("StRaWbErRy"), "X", ignore.case = FALSE), 0L)
})

Try the charcuterie package in your browser

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

charcuterie documentation built on April 3, 2025, 8:53 p.m.