tests/testthat/test-predict-mevr.R

test_that("predict.mevr", {
  describe("predict.mevr function", {
    
    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)
    sample_data <- sample_data %>%
      filter(val >= 0 & !is.na(val))
    
    # it("should throw an error if object is not a TMEV fit", {
    #   fit <- fsmev(sample_data)
    #   expect_error(predict.mevr(fit), "data object must be of type 'mevr'")
    # })
    
    it("should throw an error if type of fit is not 'tmev'", {
      fit <- fsmev(sample_data)
      expect_error(predict.mevr(fit), "fitted object must be of type 'tmev'")
    })
    
    it("should correctly predict TMEV parameters for valid input", {
      fit <- ftmev(sample_data, minyears = 8)
      result <- predict.mevr(fit)
      # Check if the result has the expected structure
      expect_true("year" %in% names(result))
      expect_true("yday" %in% names(result))
      expect_true("c.pred" %in% names(result))
      expect_true("w.pred" %in% names(result))
      # Add more assertions based on what you expect the output to be
    })
    
  })
})

Try the mevr package in your browser

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

mevr documentation built on June 30, 2024, 9:06 a.m.