From 5a6689cf1a64986e7d1e0ace64512207638e8ad5 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sun, 24 May 2026 00:47:01 +0200 Subject: [PATCH] test: 100% coverage for cmo + dema + donchian + dpo + ease_of_movement (#23) * test(cmo): cover period/value accessors + name metadata Codecov flagged 9 lines in crates/wickra-core/src/indicators/cmo.rs (file at 92.30%): const accessors period (66-68), value (71-73) and Indicator-impl name (134-136). cmo.rs now at 117/117. * test(dema): cover period accessor + warmup/name metadata Codecov flagged 9 lines in crates/wickra-core/src/indicators/dema.rs (file at 85.00%): const accessor period (43-45), Indicator-impl warmup_period (63,65,66) and name (72-74). dema.rs now at 60/60. * test(donchian): cover period accessor + warmup/name metadata Codecov flagged 9 lines in crates/wickra-core/src/indicators/donchian.rs (file at 90.21%): const accessor period (57-59), Indicator-impl warmup_period (95-97), name (103-105). donchian.rs now at 92/92. * test(dpo): cover period/value accessors + name metadata Codecov flagged 9 lines in crates/wickra-core/src/indicators/dpo.rs (file at 91.74%): const accessors period (73-75), value (83-85) and Indicator-impl name (132-134). dpo.rs now at 109/109. * test(ease_of_movement): cover period/divisor accessors + name metadata Codecov flagged 9 lines in crates/wickra-core/src/indicators/ease_of_movement.rs (file at 94.15%): const accessors period (83-85), divisor (88-90) and Indicator-impl name (141-143). ease_of_movement.rs now at 154/154. --- crates/wickra-core/src/indicators/cmo.rs | 15 +++++++++++++++ crates/wickra-core/src/indicators/dema.rs | 13 +++++++++++++ crates/wickra-core/src/indicators/donchian.rs | 11 +++++++++++ crates/wickra-core/src/indicators/dpo.rs | 16 ++++++++++++++++ .../src/indicators/ease_of_movement.rs | 12 ++++++++++++ 5 files changed, 67 insertions(+) diff --git a/crates/wickra-core/src/indicators/cmo.rs b/crates/wickra-core/src/indicators/cmo.rs index 279e31fb..2b07bc75 100644 --- a/crates/wickra-core/src/indicators/cmo.rs +++ b/crates/wickra-core/src/indicators/cmo.rs @@ -147,6 +147,21 @@ mod tests { assert!(matches!(Cmo::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessors `period` / `value` (66-73) and the + /// Indicator-impl `name` body (134-136). Existing tests inspect + /// CMO output but never query the metadata. + #[test] + fn accessors_and_metadata() { + let mut cmo = Cmo::new(14).unwrap(); + assert_eq!(cmo.period(), 14); + assert_eq!(cmo.name(), "CMO"); + assert_eq!(cmo.value(), None); + for i in 1..=15 { + cmo.update(f64::from(i)); + } + assert!(cmo.value().is_some()); + } + #[test] fn reference_value() { // CMO(3) over [10, 11, 10, 12]: changes +1, −1, +2. diff --git a/crates/wickra-core/src/indicators/dema.rs b/crates/wickra-core/src/indicators/dema.rs index c8c240cc..4f0d9742 100644 --- a/crates/wickra-core/src/indicators/dema.rs +++ b/crates/wickra-core/src/indicators/dema.rs @@ -127,4 +127,17 @@ mod tests { fn rejects_zero_period() { assert!(Dema::new(0).is_err()); } + + /// Cover the const accessor `period` (43-45) and the Indicator-impl + /// `warmup_period` (63-66) + `name` (72-74). Existing tests never + /// inspect these metadata methods. + #[test] + fn accessors_and_metadata() { + let dema = Dema::new(5).unwrap(); + assert_eq!(dema.period(), 5); + // EMA1 seeds at period (5), EMA2 needs another (period - 1) = 4 -> + // total warmup = 2*period - 1 = 9. + assert_eq!(dema.warmup_period(), 9); + assert_eq!(dema.name(), "DEMA"); + } } diff --git a/crates/wickra-core/src/indicators/donchian.rs b/crates/wickra-core/src/indicators/donchian.rs index 546fb3db..a2f67834 100644 --- a/crates/wickra-core/src/indicators/donchian.rs +++ b/crates/wickra-core/src/indicators/donchian.rs @@ -155,6 +155,17 @@ mod tests { assert!(Donchian::new(0).is_err()); } + /// Cover the const accessor `period` (57-59) and the Indicator-impl + /// `warmup_period` (95-97) + `name` (103-105). Existing tests never + /// inspect these metadata methods. + #[test] + fn accessors_and_metadata() { + let d = Donchian::new(20).unwrap(); + assert_eq!(d.period(), 20); + assert_eq!(d.warmup_period(), 20); + assert_eq!(d.name(), "DonchianChannels"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..20) diff --git a/crates/wickra-core/src/indicators/dpo.rs b/crates/wickra-core/src/indicators/dpo.rs index 35b11597..d3aa627b 100644 --- a/crates/wickra-core/src/indicators/dpo.rs +++ b/crates/wickra-core/src/indicators/dpo.rs @@ -145,6 +145,22 @@ mod tests { assert!(matches!(Dpo::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessors `period` / `value` (73-85) and the + /// Indicator-impl `name` body (132-134). `shift` is already covered + /// by `shift_is_half_period_plus_one`; `warmup_period` by + /// `reference_values`. + #[test] + fn accessors_and_metadata() { + let mut dpo = Dpo::new(20).unwrap(); + assert_eq!(dpo.period(), 20); + assert_eq!(dpo.name(), "DPO"); + assert_eq!(dpo.value(), None); + for i in 1..=dpo.warmup_period() { + dpo.update(f64::from(u32::try_from(i).unwrap())); + } + assert!(dpo.value().is_some()); + } + #[test] fn shift_is_half_period_plus_one() { assert_eq!(Dpo::new(20).unwrap().shift(), 11); diff --git a/crates/wickra-core/src/indicators/ease_of_movement.rs b/crates/wickra-core/src/indicators/ease_of_movement.rs index 0898eb66..aadca4f4 100644 --- a/crates/wickra-core/src/indicators/ease_of_movement.rs +++ b/crates/wickra-core/src/indicators/ease_of_movement.rs @@ -236,6 +236,18 @@ mod tests { assert!(EaseOfMovement::with_divisor(14, f64::NAN).is_err()); } + /// Cover the const accessors `period` / `divisor` (82-90) and the + /// Indicator-impl `name` body (141-143). Existing tests inspect EMV + /// output but never query the metadata methods. + #[test] + fn accessors_and_metadata() { + let emv = EaseOfMovement::new(14).unwrap(); + assert_eq!(emv.period(), 14); + // The canonical divisor (per the new() default) — keep in sync with src. + assert_relative_eq!(emv.divisor(), 100_000_000.0, epsilon = 1e-6); + assert_eq!(emv.name(), "EaseOfMovement"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..30)