tests/testthat/test-events.R

library(testthat)
library(campsismod)

context("Test all methods from the events class")

test_that("Add, length, contains, get_by_name methods work as expected", {
  events <- Events()

  event1 <- Event(name = "Event 1", times = 5, fun = function(id, time) {
    # Do something
  })

  event2 <- Event(name = "Event 2", times = c(5, 10), fun = function(id, time) {
    # Do something
  })

  # Add both events to list
  events <- events %>% add(event1) %>% add(event2)

  expect_equal(events %>% length(), 2)

  # Retrieve event times
  times <- events %>% get_times()
  expect_equal(times, c(5, 10))
})

test_that("Empty events list", {
  events <- Events()
  expect_equal(events %>% length(), 0)

  # Retrieve event times
  times <- events %>% get_times()
  expect_equal(times, numeric(0))
})

Try the campsis package in your browser

Any scripts or data that you put into this service are public.

campsis documentation built on Aug. 5, 2026, 9:07 a.m.