context("Generic tests")
test_that("Sanity checks", {
  expect_error(
    CST_Calibration(data = 1),
    "Parameter 'data' must be a list as output of Load function
from s2dverification package")
  
  mod1 <- 1 : (1 * 3 * 4 * 5 * 6 * 7)
  obs1 <- 1 : (1 * 1 * 4 * 5 * 6 * 7)
  dim(mod1) <- c(dataset = 1, member = 3, sdate = 4, ftime = 5, lat = 6, lon = 7)
  dim(obs1) <- c(dataset = 1, member = 1, sdate = 4, ftime = 5, lat = 6, lon = 7)
  lon <- seq(0, 30, 5)
  lat <- seq(0, 25, 5)
  data <- list(mod = mod1, obs = obs1, lat = lat, lon = lon)
  
  expect_equal(length(CST_Calibration(data = data)), 3)
  expect_equal(dim(CST_Calibration(data = data)$calibration), 
            c(dataset = 1, member = 3, sdate = 4, ftime = 5, lat = 6, lon = 7))
  expect_equal(CST_Calibration(data = data)$lat, lat)
  expect_equal(CST_Calibration(data = data)$lon, lon)
  
  data <- list(mod = mod1, obs = mod1, lat = lat, lon = lon)
  expect_error(CST_Calibration(data = data),
               "The length of the dimension 'member' in 'data$obs' must be equal to 1.")
  
  mod2 <- mod1
  mod2[1, 2, 1, 1, 1, 1] <- NA
  data <- list(mod = mod2, obs = obs1, lat = lat, lon = lon)
  expect_warning(
    CST_Calibration(data = data),
    "Parameter 'exp' contains NA values.")
  
  obs2 <- obs1
  obs2[1, 1, 2, 1, 1, 1] <- NA
  data <- list(mod = mod1, obs = obs2, lat = lat, lon = lon)
  expect_warning(
    CST_Calibration(data = data),
    "Parameter 'obs' contains NA values.")
  
  data <- list( mod = mod2, obs = obs2, lat = lat, lon = lon)
  expect_warning(
    CST_Calibration(data = data),
    "Parameter 'obs' contains NA values", "Parameter 'exp' contains NA values")
})  