context("Generic tests")
test_that("Sanity checks", {
  expect_error(
    Season(var = "A"), "Parameter 'var' must be a numeric array.") 
  expect_error(
    Season(var = 1, monini = "A", moninf = "B", monsup = "C"),
    "Parameter 'monini' must be numeric.")
  expect_error(
    Season(var = 1, monini = 1, moninf = "B", monsup = "C"),
    "Parameter 'moninf' must be numeric.")
  expect_error(
    Season(var = 1, monini = 1, moninf = 1, monsup = "C"),
    "Parameter 'monsup' must be numeric.")
  expect_error(
    Season(var = 1, monini = 1.5, moninf = 1, monsup = "C"),
    "Parameter 'monini' must be an integer.")
  expect_error(
    Season(var = 1, monini = 1, moninf = 1.5, monsup = "C"),
    "Parameter 'moninf' must be an integer.")
 expect_error(
    Season(var = 1, monini = 1, moninf = 1, monsup = 1.5),
    "Parameter 'monsup' must be an integer.")
  expect_warning(
    Season(var = 1, monini = c(1, 2), moninf = 1, monsup = 1),
   "Parameter 'monini' has length > 1 and only the first element will be used.")
  
  expect_warning(
    Season(var = 1, monini = 1, moninf = c(1, 2), monsup = 1),
   "Parameter 'moninf' has length > 1 and only the first element will be used.")
  
  expect_warning(
    Season(var = 1, monini = 1, moninf = 1, monsup = c(1, 2)),
   "Parameter 'monsup' has length > 1 and only the first element will be used.")

   expect_error(
    Season(var = 1, monini = 1, moninf = 1, monsup = 1, operation = "RRR"),
    "Could not find the function 'RRR'.")

  expect_error(Season(var = NULL), "Parameter 'var' cannot be NULL.")

  var <- array(1 : 20, dim = c(2, 4, 5))
  expect_error(Season(var),
               "Parameter 'var' must contain dimesnion names.") 
  names(dim(var)) <- c('x', 'y', 'time')
  output <- array(1 : 8, dim = c(x = 2, y = 4))
  expect_equal(
    Season(var, monini = 1, moninf = 1, monsup = 1), output)
  output <- array(5 : 12, dim = c(x = 2, y = 4))
  expect_equal(
    Season(var, monini = 1, moninf = 1, monsup = 2), output)
  output <- array(rep(seq(1.5, 19.5, 2),2), dim = c(y = 4, time = 5))
  expect_equal(
    Season(var, posdim = 1, monini = 1, moninf = 1, monsup = 2), output)

})

