test-Composite.R 1.2 KB
Newer Older
context("Generic tests")
test_that("Sanity checks", {

  expect_error(
    Composite(var = array(1:20, dim = c(2, 5, 2)), c(1, 1, 0)),
aho's avatar
aho committed
    "Temporal dimension of var is not equal to length of occ.")

  expect_warning(
    Composite(var = array(1:40, dim = c(2, 5, 4)), c(1, 2, 2, 2)),
    "Composite 1 has length 1 and pvalue is NA.")

  var <- array(rep(c(1, 3, 2, 1, 2), 8), dim = c(x = 2, y = 4, time = 5))
  occ <- c(1, 2, 2, 2, 1)
nperez's avatar
nperez committed
  output <- c(x = 2, y = 4, composite = 2)  #dim(asd$composite)
  expect_equal(
    dim(Composite(var, occ)$composite),
    output
  )
  output <- c(1.5, 2.0, 2.5, 2.0)
  expect_equal(
    Composite(var, occ)$composite[1, , 1],
    output
  )

  var <- array(rep(c(1, 3, 2, 1, 2, 2), 8), dim = c(x = 2, y = 4, time = 6))
  occ <- c(1, 1, 2, 2, 3, 3)
  output <- matrix(c(1.5, 2.5, 1.5, 2.0, 2.0, 1.5, 1.5, 2.5), 2, 4)
aho's avatar
aho committed
  expect_equivalent(
    Composite(var, occ)$composite[, , 2],
aho's avatar
aho committed
  expect_equal(
    dim(Composite(var, occ, K = 2)$composite),
    c(x = 2, y = 4, composite = 2)
  )
  expect_equal(
    Composite(var, occ, K = 3),
    Composite(var, occ)
  )
  expect_equal(
    Composite(var, occ, K = 4)$composite[1, 1, ],
    c(1.5, 1.5, 2.0, NA),
    tolerance = 0.01
  )