context("Generic tests")
test_that("Sanity checks", {

#error
  expect_error(
    Eno(NULL),
    "Parameter 'obs' cannot be NULL."
  )

  expect_error(
    Eno(c('a', 'b'), posdim = 1),
    "Parameter 'obs' must be a numeric array."
  )

  expect_error(
    Eno(1:10, c()),
    "Parameter 'posdim' cannot be NULL."
  )

  expect_error(
    Eno(1:10, posdim = FALSE),
    "Parameter 'posdim' must be an positive integer or character."
  )

  expect_error(
    Eno(1:10, posdim = -1),
    "Parameter 'posdim' must be a positive integer or character."
  )

  expect_error(
    Eno(1:10, posdim = 1.2),
    "Parameter 'posdim' must be a positive integer or character."
  )

  expect_error(
    Eno(array(1:10, dim = c(2, 5)), 3),
    "Parameter 'posdim' excesses the dimension length of parameter 'obs'."
  )

  dat <- array(1:10, dim = c(2, 5))
  expect_error(
    Eno(dat, 'a'),
    paste0("Parameter 'obs' doesn't have dimension names. ",
           "Add names or specify parameter 'posdim' by number.")
  )

  names(dim(dat)) <- c('a', 'b')
  expect_error(
    Eno(dat, 'c'),
    paste0("Parameter 'posdim' does not match any dimension name of ",
           "parameter 'obs'.")
  )

  expect_error(
    Eno(dat, 'a', na.action = na.stop),
    "Parameter 'na.action' must be either 'na.pass' or 'na.fail'."
  )

  dat[1] <- NA
  expect_error(
    Eno(dat, 'a', na.action = na.fail),
    paste0("NA value in paratemter 'obs', which is not accepted when ",
           "parameter 'na.action' = 'na.fail'.")
  )

  expect_error(
    Eno(dat, 'a', ncores = FALSE),
    "Parameter 'ncores' must be a positive integer."
  )

  expect_error(
    Eno(dat, 'a', ncores = 1.5),
    "Parameter 'ncores' must be a positive integer."
  )

#equal
  dat <- array(1:10, dim = c(2, 5))

  expect_equal(
    names(dim(Eno(dat, 1))),
     c('D2')
  )

  names(dim(dat)) <- c('a', 'b')
  expect_equal(
    Eno(dat, 1),
     array(rep(2, 5), dim = c(b = 5))
  )

  dat[1] <- NA
  expect_equal(
    Eno(dat, 2)[1],
    4
  )

  expect_equal(
    Eno(dat, 1)[1],
    as.numeric(NA)
  )

})

