tests/testthat/test-runningratio.R

context("running ratio")

test_that("running ratio stops when it should", {

  expect_error( runningratio(c(0,1), c(0,0), 1) )
  expect_error( runningratio(c(0,1), 0, c(1,1)) )
  expect_error( runningratio(0, c(0,0), c(1,1)) )
  expect_error( runningratio(0, c(0,0), c(1,1,2)) )

})


test_that("running ratio with constant x or position", {

  n <- 100
  d <- 5
  x <- rnorm(n)
  pos <- rep(0, n)
  denom <- rep(d, n)

  expect_equal( runningratio(pos, x, denom, window=1), rep(mean(x)/d, n) )

  mu <- mean(x)
  x <- rep(mu, n)
  pos <- runif(n, 0, 5)

  expect_equal( runningratio(pos, x, denom, window=1), x/d)

})

Try the broman package in your browser

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

broman documentation built on June 8, 2025, 9:40 p.m.