tests/testthat/test_util_roll_sum.R

context("util_roll_sum related tests")

test_that("util_roll_sum works", {
  time_step <- 10
  units <- "mins"

  hyet <- tibble::tibble(
    date = seq(
      from = as.POSIXct(0, origin = "2018-01-01"), length.out = 10,
      by = paste(time_step, units)
    ),
    prec = 1:10
  )

  # if windows size is greater than records length return all NA
  expect_true(all(is.na(util_roll_sum(hyet, 11)$prec)))

  # fill with zeros
  expect_equal(util_roll_sum(hyet, 2)$prec, c(seq(3, 19, 2), 0))
  expect_equal(util_roll_sum(hyet, 3)$prec, c(seq(6, 27, 3), 0, 0))
})
kvantas/hyetor documentation built on Sept. 2, 2019, 12:57 a.m.