tests/testthat/test-return-levels.R

test_that("return-levels should correctly calculate SMEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2005-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  result <- return.levels.mev(fsmev(data))
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
})

test_that("return-levels should correctly calculate MEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2005-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  result <- return.levels.mev(fmev(data))
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
})

test_that("return-levels should correctly calculate TMEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2010-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  result <- return.levels.mev(ftmev(data, minyears = 8))
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
})

#---------------------------------------------
# confidence intervals use parallel processing
test_that("return-levels should correctly calculate confidence intervals for SMEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2005-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  fit <- fsmev(data)
  result <- return.levels.mev(
    fit,
    ci = TRUE,
    alpha = 0.2,
    R = 10,
    ncores = 2
  )
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
  expect_true("ci" %in% names(result))
})

test_that("return-levels should correctly calculate confidence intervals for MEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2005-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  fit <- fmev(data)
  result <- return.levels.mev(fit, ci = TRUE, alpha = 0.2, R = 10, ncores = 2)
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
  expect_true("ci" %in% names(result))
})

test_that("return-levels should correctly calculate confidence intervals for TMEV return levels for valid input", {
  # Setup a mock dataset
  set.seed(123)
  sample_dates <- seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2010-01-01"),
    by = "day"
  )
  sample_data <- data.frame(
    groupvar = sample_dates,
    val = sample(rnorm(length(sample_dates)))
  )
  sample_data$groupvar <- as.Date(sample_data$groupvar)
  data <- sample_data %>%
    filter(val >= 0 & !is.na(val))
  fit <- ftmev(data, minyears = 7)
  result <- return.levels.mev(fit, ci = TRUE, alpha = 0.2, R = 10, ncores = 2)
  # Check if the result has the expected structure
  expect_true("rl" %in% names(result))
  expect_true("ci" %in% names(result))
})

Try the mevr package in your browser

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

mevr documentation built on Oct. 13, 2026, 5:07 p.m.