tests/testthat/test-aoristic-datacheck.R

test_that("aoristic.datacheck validates columns, datetimes, and coordinates", {
  data <- make_events("2024-01-07 10:00:00", "2024-01-07 11:00:00")
  expect_error(aoristic.datacheck(data, "bad", "y", "from", "to"), "bad")

  character_time <- data
  character_time$from <- format(character_time$from)
  expect_error(aoristic.datacheck(character_time, "x", "y", "from", "to"), "DateTimeFrom.*POSIXct")

  bad_coordinates <- data
  bad_coordinates$x <- "east"
  expect_error(aoristic.datacheck(bad_coordinates, "x", "y", "from", "to"), "X coordinate.*numeric")
})

test_that("aoristic.datacheck flags missing ends and reversed intervals", {
  data <- make_events(
    c("2024-01-07 10:00:00", "2024-01-07 12:00:00", NA_character_),
    c(NA_character_, "2024-01-07 11:00:00", "2024-01-07 13:00:00")
  )
  result <- suppressMessages(aoristic.datacheck(data, "x", "y", "from", "to"))
  expect_equal(result$aoristic_datacheck, c(1, 2, 0))
})

test_that("coordinate NA and zero values are reported", {
  data <- make_events(
    c("2024-01-07 10:00:00", "2024-01-07 11:00:00"),
    c("2024-01-07 10:30:00", "2024-01-07 11:30:00"),
    x = c(NA_real_, 0), y = c(1, 2)
  )
  messages <- capture.output(
    invisible(aoristic.datacheck(data, "x", "y", "from", "to")),
    type = "message"
  )
  expect_match(paste(messages, collapse = "\n"), "1 rows missing spatial coordinates")
  expect_match(paste(messages, collapse = "\n"), "1 rows had a zero spatial coordinate")
})

Try the aoristic package in your browser

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

aoristic documentation built on Sept. 9, 2026, 9:08 a.m.