# tests/testthat/test-utils.R library(testthat) library(Athlytics) # To make internal functions available if using devtools::load_all() library(lubridate) context("Utility Functions") test_that("english_month_year correctly formats dates", { # Test with a single date single_date <- ymd("2023-01-15") expect_equal(english_month_year(single_date), "Jan 2023") # Test with multiple dates multiple_dates <- c(ymd("2023-03-10"), ymd("2024-11-05")) expect_equal(english_month_year(multiple_dates), c("Mar 2023", "Nov 2024")) # Test with dates spanning year-end year_end_dates <- c(ymd("2022-12-25"), ymd("2023-01-01")) expect_equal(english_month_year(year_end_dates), c("Dec 2022", "Jan 2023")) # Test with a leap year date leap_date <- ymd("2024-02-29") expect_equal(english_month_year(leap_date), "Feb 2024") # Test with an empty vector of dates (should return empty character vector) empty_dates <- ymd(character(0)) expect_equal(english_month_year(empty_dates), character(0)) # Test with NA date # expect_equal(english_month_year(ymd(NA)), NA_character_) }) test_that("calculate_pace works correctly", { # Test standard pace calculation expect_equal(calculate_pace(3600, 10), 6) # 1 hour for 10 km = 6 min/km expect_equal(calculate_pace(1800, 5), 6) # 30 min for 5 km = 6 min/km # Test edge cases expect_equal(calculate_pace(0, 10), Inf) # No time = infinite pace expect_equal(calculate_pace(3600, 0), Inf) # No distance = infinite pace # Test very fast pace expect_equal(calculate_pace(600, 3), 200/60) # 10 min for 3 km # Test negative values expect_equal(calculate_pace(-100, 10), -10/60) })