tests/testthat/test_utils.R

context('utils')

test_that('reduce works', {
  expect_equal(reduce(1:10, function(x, y) x + y), sum(1:10))
  expect_equal(reduce(1:20, .init=1, function(x, y) x + y), sum(1:20)+1)
  expect_equal(reduce(as.list(1:20), function(x, y) x + y), sum(1:20))
  expect_equal(reduce(c(T, F, T), function(x, y) x & y), FALSE)
  expect_equal(reduce(c('the', 'fish', 'was', 'delish'), paste), 'the fish was delish')

  expect_equal(reduce(list(), .init=0), 0)
  expect_error(reduce(list()), "`.x` is empty, and no `.init` supplied")
})

Try the ggridges package in your browser

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

ggridges documentation built on Sept. 26, 2022, 9:07 a.m.