context("Generic tests")
test_that("Sanity checks and simple use cases", {
  # Generate simple synthetic data
  t <- rnorm(6 * 6 * 2 * 3 * 4)*10 + 273.15 + 10
  dim(t) <- c(dataset = 1, member = 2, sdate = 3, ftime = 4, lat = 6, lon = 6)
  lon <- seq(4, 9, 1)
  lat <- seq(42, 47, 1)
  exp <- list(data = t, lat = lat, lon = lon)
  o <- runif(29*29)*3000
  dim(o) <- c(lat = 29, lon = 29)
  lon <- seq(3, 10, 0.25) - 100
  lat <- seq(41, 48, 0.25) -60
  oro <- list(data = o, lat = lat, lon = lon)
  attr(oro, 'class') <- 's2dv_cube'

  expect_error(
    res <- CST_RFTemp(exp, oro, xlim=c(1,3), ylim=c(1,3)),
    "Parameter 'data' must be of the class 's2dv_cube', as output by CSTools::CST_Load."
  )
  attr(exp, 'class') <- 's2dv_cube'

  expect_error(
    res <- CST_RFTemp(exp, oro, xlim=c(1,3), ylim=c(1,3)),
    "Orography not available for selected area"
  )
  oro$lon = oro$lon + 100
  oro$lat = oro$lat + 60

  expect_error(
    res <- CST_RFTemp(exp, oro, xlim=c(3,8), ylim=c(43, 46)),
    "Downscaling area not contained in input data"
  )
  
  res <- CST_RFTemp(exp, oro, xlim=c(4,8), ylim=c(43, 46), lapse=6.5)

  dimexp=dim(exp$data)
  expect_equal(dim(res$data), c(lon=17,lat=13,
                                dimexp["dataset"], dimexp["member"],
                                dimexp["sdate"], dimexp["ftime"]))
})  
