tests/testthat/test_loops.R

## test for R/loops.R

cat("\ntest_loops.R\n")




## functions used within tests of apply
afun = function(i, x) {
  paste(i, x)
}


test_that("apply with index (basic use)", {
  ## apwi allows computing apply with explicit reference to element index
  input = c("a", "b", "c")
  expected = list("1 a", "2 b", "3 c")
  expect_equal(apwi(input, afun), expected)
})


test_that("apply with index (using names as indexes)", {
  ## apwi allows computing apply with explicit reference to element index
  input = c(AA="a", BB="b", CC="c")
  expected = list(AA="AA a", BB="BB b", CC="CC c")
  expect_equal(apwi(input, afun), expected)
})
tkonopka/shrt documentation built on March 5, 2020, 2:51 p.m.