tests/testthat/test.cumulative.R

library(testthat)
library(hablar)

context("cumulative")
test_that("cumulative", {
  expect_equal(cumsum_(c(1, 1, 1, 1)), c(1, 2, 3, 4))
  expect_equal(cumsum_(c(1, 1, NA, 1)), c(1, 2, 2, 3))

  expect_equal(cummean_(c(1, 1, NA, 1)), c(1, 1, 1, 1))
  expect_equal(cummean_(c(NA, NA, NA, NA)), as.double(c(NA, NA, NA, NA)))
  
  expect_equal(cum_unique(c(1, 2, 3, 4)), c(1, 2, 3, 4))
  expect_equal(cum_unique(c(1, 2, NA, 4)), c(1, 2, 3, 4))
  expect_equal(cum_unique_(c(1, 2, NA, 4)), c(1, 2, 2, 3))
})

Try the hablar package in your browser

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

hablar documentation built on March 31, 2023, 11:54 p.m.