<purrr_error_indexed/rlang_error/error/condition>
Error in `map(.x, .f, ...)`: ℹ In index: 1.
Caused by error in `parse_activity_file()`:
! Activity file does not exist: D:\temp\2025_10_10_06_30_16_11802\RtmpY1RSSR/D:\temp\2025_10_10_06_30_16_11802\RtmpY1RSSR/activities/1.gpx

# Comprehensive tests for all major functions
create_test_data <- function(n_days = 60) {
date = seq(Sys.Date() - n_days, Sys.Date(), by = "day"),
type = sample(c("Run", "Ride"), n_days + 1, replace = TRUE),
sport_type = sample(c("Run", "Ride"), n_days + 1, replace = TRUE),
distance = runif(n_days + 1, 5000, 20000),
moving_time = runif(n_days + 1, 1800, 7200),
elapsed_time = runif(n_days + 1, 1800, 7200),
total_elevation_gain = runif(n_days + 1, 0, 500),
average_heartrate = runif(n_days + 1, 120, 180),
max_heartrate = runif(n_days + 1, 160, 200),
average_watts = runif(n_days + 1, 150, 300),
kilojoules = runif(n_days + 1, 500, 2000),
activity_id = as.character(seq_len(n_days + 1)),
name = paste("Activity", seq_len(n_days + 1)),
start_date = seq(Sys.Date() - n_days, Sys.Date(), by = "day"),
start_date_local = seq(Sys.Date() - n_days, Sys.Date(), by = "day")
test_that("calculate_acwr works with various parameters", {
result_distance <- calculate_acwr(test_data, load_metric = "distance_km")
result_run <- calculate_acwr(test_data, activity_type = "Run")
expect_true(all(result_date$date >= Sys.Date() - 30))
test_that("calculate_exposure works with various parameters", {
result_distance <- calculate_exposure(test_data, load_metric = "distance_km")
result_run <- calculate_exposure(test_data, activity_type = c("Run"))
test_data$filename <- paste0("activities/", test_data$activity_id, ".gpx")
# Test with valid data (should work without warnings)
# Test with data that has no heart rate (should warn)
# Test should handle the case where no stream data is available
# Will produce multiple warnings about missing files, then a final warning about no valid data
result <- calculate_decoupling(test_data, export_dir = tempdir()),
test_that("plot functions work with data frames", {
p2 <- plot_acwr(test_acwr, highlight_zones = TRUE)
p4 <- plot_exposure(test_exposure, risk_zones = TRUE)
test_that("enhanced plotting functions work", {
p2 <- plot_acwr_enhanced(test_acwr, show_ci = TRUE)
# Test plot_acwr_comparison with RA and EWMA methods
# This function expects two dataframes, not a list
test_acwr2 <- calculate_acwr(create_test_data(90), acute_period = 5, chronic_period = 21)
date = rep(seq(Sys.Date() - 29, Sys.Date(), by = "day"), 10),
acwr_smooth = rnorm(300, mean = 1.0, sd = 0.3),
sport = "Run"  # Use single sport to avoid grouping issues in test
# Test cohort_reference without grouping
result <- cohort_reference(ref_data, by = NULL)
result2 <- cohort_reference(ref_data, metric = "acwr_smooth", by = NULL)
# Test add_reference_bands - it needs a ggplot object
date = seq(Sys.Date() - 29, Sys.Date(), by = "day"),
acwr_smooth = rnorm(30, mean = 1.0, sd = 0.2)
p <- ggplot(individual_data, aes(x = date, y = acwr_smooth)) + geom_line()
test_that("load_local_activities works with test export", {
skip("Skipping file system test - requires actual export structure")
# Note: This test requires a real Strava export structure
# In production, load_local_activities should be tested with actual export files
# For now, we skip this test in automated testing
# Create mock flagged stream data (as if from flag_quality)
flag_hr_spike = sample(c(TRUE, FALSE), 100, replace = TRUE, prob = c(0.1, 0.9)),
flag_pw_spike = sample(c(TRUE, FALSE), 100, replace = TRUE, prob = c(0.1, 0.9)),
flag_gps_drift = sample(c(TRUE, FALSE), 100, replace = TRUE, prob = c(0.1, 0.9)),
flag_any = sample(c(TRUE, FALSE), 100, replace = TRUE, prob = c(0.2, 0.8)),
is_steady_state = sample(c(TRUE, FALSE), 100, replace = TRUE, prob = c(0.6, 0.4)),
# Just check that the function exists (it's internal)
test_that("all color palette functions work", {