tests/testthat/test-coverage.R

test_that("monthly coverage", {
  x <- data.frame(
    date = seq(as.Date("1990-01-01"), as.Date("1990-12-31"), by = "day")
  )
  x$month <- as.numeric(format(x$date, "%m"))
  x$tmin <- ifelse(x$month %% 2 == 0, 1, NA)
  x <- as_daily(x)
  expect_equal(
    monthly_coverage(x)[["monthly_coverage_tmin"]],
    rep(c(0, 1), 6)
  )
})

test_that("annual coverage", {
  x <- data.frame(
    date = seq(as.Date("1990-01-01"), as.Date("1991-12-31"), by = "day")
  )
  x$tmin <- rep(c(NA, 1), nrow(x) / 2)
  x$tmax <- rep(c(NA, 1), each = nrow(x) / 2)
  x <- as_daily(x)
  expect_equal(
    annual_coverage(x)[["annual_coverage_tmax"]],
    c(0, 1)
  )
  expect_equal(
    annual_coverage(x)[["annual_coverage_tmin"]],
    c(.5, .5),
    tolerance = 1e-2
  )
})

Try the GHCNr package in your browser

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

GHCNr documentation built on April 3, 2025, 11:16 p.m.