Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/testthat/test-agent_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,22 @@ test_that("does_param_set_exist works with subset of columns", {
})

test_that("extract_json_object parses simple JSON", {
skip_if_not_installed("jsonlite")
raw <- '{"key": "value", "num": 42}'
result <- extract_json_object(raw)
expect_equal(result$key, "value")
expect_equal(result$num, 42)
})

test_that("extract_json_object strips code fences", {
skip_if_not_installed("jsonlite")
raw <- '```json\n{"key": "value"}\n```'
result <- extract_json_object(raw)
expect_equal(result$key, "value")
})

test_that("extract_json_object handles surrounding text", {
skip_if_not_installed("jsonlite")
raw <- 'Here is the JSON: {"answer": "yes"} and some more text.'
result <- extract_json_object(raw)
expect_equal(result$answer, "yes")
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# -- target_corr_fn tests --

test_that("target_corr_fn returns correlated features", {
skip_if_not_installed("corrr")
set.seed(123)
n <- 50
x1 <- rnorm(n)
Expand All @@ -23,6 +24,7 @@ test_that("target_corr_fn returns correlated features", {
})

test_that("target_corr_fn respects threshold", {
skip_if_not_installed("corrr")
set.seed(42)
n <- 50
x1 <- rnorm(n)
Expand All @@ -41,6 +43,7 @@ test_that("target_corr_fn respects threshold", {
})

test_that("target_corr_fn handles single feature", {
skip_if_not_installed("corrr")
set.seed(123)
n <- 30
data <- tibble::tibble(
Expand All @@ -55,6 +58,7 @@ test_that("target_corr_fn handles single feature", {
})

test_that("target_corr_fn handles no correlated features", {
skip_if_not_installed("corrr")
set.seed(999)
n <- 100
data <- tibble::tibble(
Expand All @@ -72,6 +76,8 @@ test_that("target_corr_fn handles no correlated features", {
# -- Variable importance function tests --

test_that("vip_rf_fn produces variable importance scores", {
skip_if_not_installed("ranger")
skip_if_not_installed("vip")
set.seed(42)
data <- tibble::tibble(
Date = seq(as.Date("2020-01-01"), by = "day", length.out = 100),
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-parallel_util.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test_that("par_start returns correct packages for sequential processing", {
})

test_that("par_start with local_machine creates cluster", {
skip_if(parallel::detectCores() <= 1, "Requires more than one core")
run_info <- list(
storage_object = NULL,
path = tempdir(),
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-utility.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# tests/testthat/test-utility.R

test_that("get_timestamp returns a POSIXct object in UTC", {
ts <- get_timestamp()

expect_s3_class(ts, "POSIXct")
expect_equal(attr(ts, "tzone"), "UTC")
})

test_that("get_timestamp returns a timestamp close to current time", {
ts <- get_timestamp()
now_utc <- as.POSIXct(format(Sys.time(), tz = "UTC"), tz = "UTC")

# should be within 60 seconds of now to avoid flaky failures on slow CI
expect_true(abs(difftime(ts, now_utc, units = "secs")) < 60)
})

test_that("get_timestamp format is YYYYMMDDTHHMMSSZ", {
ts <- get_timestamp()
formatted <- format(ts, "%Y%m%dT%H%M%SZ")

# should be parseable back
parsed <- as.POSIXct(formatted, format = "%Y%m%dT%H%M%SZ", tz = "UTC")
expect_false(is.na(parsed))
})