context("s2dv::RandomWalkTest tests")

##############################################
  set.seed(1)
  dat1_A <- array(rnorm(64), dim = c(sdate = 4, ftime = 4, lat = 2, lon = 2))
  set.seed(2)  
  dat1_B <- array(rnorm(64), dim = c(sdate = 4, ftime = 4, lat = 2, lon = 2))


##############################################
test_that("1. Input checks", {

  expect_error(
  RandomWalkTest(c(), dat1_B),
  "Parameters 'skill_A' and 'skill_B' cannot be NULL."
  )
  expect_error(
  RandomWalkTest(dat1_A, 'a'),
  "Parameters 'skill_A' and 'skill_B' must be a numerical array."
  )
  expect_error(
  RandomWalkTest(array(1:10, dim = c(2, 5)), array(1:12, dim = c(2, 6))),
  "Parameters 'skill_A' and 'skill_B' must have the same dimensions."
  )
  expect_error(
  RandomWalkTest(1:10, 2:11, time_dim = 12),
  "Parameter 'time_dim' must be a character string."
  )
  expect_error(
  RandomWalkTest(dat1_A, dat1_B, time_dim = 'date'),
  "Parameter 'time_dim' is not found in 'skill_A' or 'skill_B' dimension."
  )
  expect_error(
  RandomWalkTest(dat1_A, dat1_B, ncores = T),
  "Parameter 'ncores' must be a positive integer."
  )

})

##############################################
test_that("2. Output checks: dat1", {
  res <- RandomWalkTest(dat1_A, dat1_B)

  expect_equal(
  length(res),
  2
  )
  expect_equal(
  names(res),
  c("score", "signif")
  )
  expect_equal(
  dim(res$score),
  c(ftime = 4, lat = 2, lon = 2)
  )
  expect_equal(
  dim(res$signif),  
  c(ftime = 4, lat = 2, lon = 2)
  )
  expect_equal(
  is.numeric(res$score),
  TRUE
  )
  expect_equal(
  is.logical(res$signif),
  TRUE
  )
  expect_equal(
  mean(res$score, na.rm = T),
  0
  )
  expect_equal(
  res$score[, 1, 1],
  c(0, 0, -2, -2)
  )
  expect_equal(
  res$score[, 1, 2],
  c(0, 4, 2, 0)
  )

})
