##############################################
  # dat1
  set.seed(1)
  exp1 <- array(rnorm(12), c(dat = 1, member = 2, year = 3, time = 2)) 
  set.seed(2)
  obs1 <- array(rnorm(6), c(dat = 1, year = 3, time = 2))

  # dat2
  exp2 <- exp1
  exp2[1, 1, 2, 1] <- NA
  obs2 <- obs1

##############################################

test_that("1. Input checks", {

  expect_error(
  RatioPredictableComponents(c()),
  "Parameter 'exp' cannot be NULL."
  )
  expect_error(
    RatioPredictableComponents(c(NA, NA)),
    "Parameter 'exp' must be a numeric array."
  )
  expect_error(
  RatioPredictableComponents(exp1, c()),
  "Parameter 'obs' cannot be NULL."
  )
  expect_error(
    RatioPredictableComponents(exp1, c(NA, NA)),
    "Parameter 'obs' must be a numeric array."
  )
  expect_error(
    RatioPredictableComponents(exp1, obs1, time_dim = 'a'),
    "'exp' must have 'time_dim' dimension."
  )
  expect_error(
    RatioPredictableComponents(exp1, obs1, member_dim = 'ens'),
    "'exp' must have 'member_dim' dimension."
  )
  expect_error(
    RatioPredictableComponents(exp1, array(rnorm(6), dim = c(sdate = 3, time = 2))),
    "'obs' must have 'time_dim' dimension."
  )
  expect_error(
    RatioPredictableComponents(exp1, array(rnorm(4), dim = c(year = 2, time = 2))),
    "'exp' and 'obs' must have the same length for 'time_dim'."
  )
  expect_error(
    RatioPredictableComponents(exp1, obs1, na.rm = 'TRUE'),
    "Parameter 'na.rm' must be TRUE or FALSE."
  )
  expect_error(
    RatioPredictableComponents(exp1, obs1, ncore = 0),
    "Parameter 'ncores' must be a positive integer."
  )

})

##############################################
test_that("2. Output checks: dat1", {

expect_equal(
dim(RatioPredictableComponents(exp1, obs1)),
c(dat = 1, time = 2)
)
expect_equal(
dim(RatioPredictableComponents(exp1, obs1, time_dim = 'time')),
c(dat = 1, year = 3)
)
expect_equal(
as.vector(RatioPredictableComponents(exp1, obs1)),
c(-0.29462414, 0.07955797),
tolerance = 0.0001
)
expect_equal(
as.vector(RatioPredictableComponents(exp1, obs1, time_dim = 'time')),
c(-1.054665, 6.843041, -1.000069),
tolerance = 0.0001
)

})

test_that("2. Output checks: dat2", {

expect_equal(
as.vector(RatioPredictableComponents(exp2, obs2, na.rm = T)),
c(-0.07981636, 0.07955797),
tolerance = 0.0001
)
expect_equal(
as.vector(RatioPredictableComponents(exp2, obs2, na.rm = F)),
c(NA, 0.07955797),
tolerance = 0.0001
)
})

