test_that( "amr_ewma returns the expected output", { x <- c( 0.20, 0.21, 0.19, 0.22, 0.23, 0.25, 0.40, 0.45 ) result <- amr_ewma(x) expect_s3_class( result, "data.frame" ) expect_equal( nrow(result), length(x) ) expect_true( all( c( "observation", "observed", "ewma", "center", "upper_limit", "lower_limit", "alert" ) %in% names(result) ) ) } ) test_that( "amr_ewma preserves observations", { x <- c( 0.10, 0.15, 0.20, 0.25, 0.30 ) result <- amr_ewma(x) expect_equal( result$observed, x ) } ) test_that( "amr_ewma produces finite EWMA values", { x <- c( 0.10, 0.12, 0.15, 0.20, 0.25 ) result <- amr_ewma(x) expect_true( all(is.finite(result$ewma)) ) expect_true( all(is.finite(result$upper_limit)) ) expect_true( all(is.finite(result$lower_limit)) ) } ) test_that( "amr_ewma rejects invalid lambda", { x <- c( 0.10, 0.20, 0.30 ) expect_error( amr_ewma( x, lambda = 0 ) ) expect_error( amr_ewma( x, lambda = 1.5 ) ) } ) test_that( "amr_ewma rejects missing values", { x <- c( 0.10, NA, 0.30 ) expect_error( amr_ewma(x) ) } ) test_that( "amr_ewma requires at least three observations", { expect_error( amr_ewma( c(0.10, 0.20) ) ) } )