
context("SignalNoiseRatio test")

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

  # dat2
  data2 <- data1
  data2[1, 1, 2, 1] <- NA

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

test_that("1. Input checks", {

  expect_error(
  SignalNoiseRatio(c()),
  "Parameter 'data' cannot be NULL."
  )
  expect_error(
    SignalNoiseRatio(c(NA, NA)),
    "Parameter 'data' must be a numeric array."
  )
  expect_error(
    SignalNoiseRatio(data1, time_dim = 'a'),
    "'data' must have 'time_dim' dimension."
  )
  expect_error(
    SignalNoiseRatio(data1, member_dim = 'ens'),
    "'data' must have 'member_dim' dimension."
  )
  expect_error(
    SignalNoiseRatio(data1, na.rm = 'TRUE'),
    "Parameter 'na.rm' must be TRUE or FALSE."
  )
  expect_error(
    SignalNoiseRatio(data1, ncore = 0),
    "Parameter 'ncores' must be a positive integer."
  )

})


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

expect_equal(
dim(SignalNoiseRatio(data1)),
c(dat = 1, time = 2)
)
expect_equal(
as.vector(SignalNoiseRatio(data1)),
c(0.1591161, 0.8003926),
tolerance = 0.0001
)

})

test_that("2. Output checks: dat2", {
expect_equal(
as.vector(SignalNoiseRatio(data2, na.rm = T)),
c(4.5075526, 0.8003926),
tolerance = 0.0001
)
expect_equal(
as.vector(SignalNoiseRatio(data2, na.rm = F)),
c(NA, 0.8003926),
tolerance = 0.0001
)

})

