tests/testthat/test-pystr_translate.R

library(pystr)
context("pystr_translate")

test_that("it translates numbers", {
  map = pystr_maketrans("123", "abc")
  expect_equal(pystr_translate("1 2 3 456", map), "a b c 456")
})

test_that("it translates chars", {
  map = pystr_maketrans("abc", "123")
  expect_equal(pystr_translate("abc456", map), "123456")
})

test_that("different things can be mapped to the same char", {
  map = pystr_maketrans("abcd", "rrrr")
  expect_equal(pystr_translate("abcdefg", map), "rrrrefg")
})

test_that("it works with a character vector", {
  map = pystr_maketrans("abc", "123")
  expect_equal(pystr_translate(c("abc456", "abcdefg"), map), c("123456", "123defg"))
})

Try the pystr package in your browser

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

pystr documentation built on April 15, 2017, 12:30 a.m.