tests/testthat/test_patient_meta.R

test_that("Entity has a meta slot for bundle bookkeeping", {
  schema <- default_entity_schema()
  schema$x <- list(type = "continuous", default = 1, coerce = as.numeric)

  p <- fluxCore::Entity$new(init = list(x = 2), schema = schema, time0 = 0)
  expect_true(is.list(p$meta))
  expect_length(p$meta, 0)

  # Bundles may store arbitrary bookkeeping here
  p$meta$refresh_clock <- list(last_refresh_time = 12)
  expect_equal(p$meta$refresh_clock$last_refresh_time, 12)

  # Meta should persist across updates
  p$update(time = 5, event_type = "lab", changes = list(x = 3))
  expect_equal(p$meta$refresh_clock$last_refresh_time, 12)

  # Meta is not a state variable
  st <- p$state()
  expect_false("meta" %in% names(st))
})

test_that("Entity$new can attach entity_type metadata", {
  p <- fluxCore::Entity$new(
    init = list(),
    schema = default_entity_schema(),
    entity_type = "entity"
  )
  expect_identical(p$meta$entity_type, "entity")
})

Try the fluxCore package in your browser

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

fluxCore documentation built on Sept. 22, 2026, 5:07 p.m.