tests/testthat/test-ContainerGeneric.R

test_that("initialise", {
  ContainerGeneric$new()
})

test_that("add", {
  MyCont <- ContainerGeneric$new()

  MyCont$add(Agent$new(toy_individuals, "pid"))
  MyCont$add(Agent$new(toy_individuals, "pid"))

  expect_length(MyCont$Cont, 2)

  checkmate::expect_r6(MyCont$Cont[[1]], classes = "Agent", null.ok = FALSE)
})

test_that("get", {
  MyCont <- ContainerGeneric$new()

  MyCont$add(Agent$new(toy_individuals, "pid"))

  checkmate::expect_r6(MyCont$get(pos = 1), classes = "Agent", null.ok = FALSE)

  expect_error(MyCont$get(pos = 2), "pos is greater than the number of available objecst in the container")

  expect_error(MyCont$get(pos = -1), "pos can not be less than or equal to 0.")

  MyCont$get(1)
})


test_that("remove", {
  MyCont <- ContainerGeneric$new()

  MyCont$add(Agent$new(toy_individuals, "pid"))
  MyCont$add(Agent$new(toy_individuals, "pid"))
  MyCont$add(Agent$new(toy_individuals, "pid"))

  expect_error(MyCont$remove(pos = 0), regexp = "pos can not be less than or equal to 0")
  expect_error(MyCont$remove(pos = 4), regexp = "pos is greater than the number of available objecst in the container")
  MyCont$remove(2)
  expect_length(MyCont$Cont, 2)
})
dymium-org/dymiumCore documentation built on July 18, 2021, 5:10 p.m.