blob: 3f438775dee6a270c374c5f2a9fb65325e92a5ab [file] [log] [blame]
Marc Kupietz7638ca42025-05-25 13:18:16 +02001test_that("benchmark time formatting function works correctly", {
2 # Create a mock environment to test the formatting function
3 format_benchmark_time <- function(time_string) {
4 if (is.character(time_string) && grepl("s$", time_string)) {
5 time_value <- as.numeric(sub("s$", "", time_string))
6 paste0(round(time_value, 2), "s")
7 } else {
8 time_string
9 }
10 }
11
12 # Test with various inputs
13 expect_equal(format_benchmark_time("3.395072759s"), "3.4s")
14 expect_equal(format_benchmark_time("0.123456s"), "0.12s")
15 expect_equal(format_benchmark_time("1.999s"), "2s")
16 expect_equal(format_benchmark_time("0.001s"), "0s")
17
18 # Test with non-matching inputs
19 expect_equal(format_benchmark_time("invalid"), "invalid")
20 expect_equal(format_benchmark_time(NULL), NULL)
21 expect_equal(format_benchmark_time(123), 123)
22})