From 645b0029586ff081408f0b9522a7ba78b128b8c3 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sun, 24 May 2026 00:47:43 +0200 Subject: [PATCH] test: 100% coverage for mom + sma + stoch_rsi + tema + trima (#25) * test(mom): cover period/value accessors + name metadata Codecov flagged 9 lines in indicators/mom.rs (file at 89.53%): const accessors period (56-58), value (61-63) and Indicator-impl name (101-103). mom.rs now at 86/86. * test(sma): cover period accessor + warmup/name metadata Codecov flagged 9 lines in indicators/sma.rs (file at 93.12%): const accessor period (70-72), Indicator-impl warmup_period (115-117), name (123-125). sma.rs now at 131/131. * test(stoch_rsi): cover periods/value accessors + name metadata Codecov flagged 9 lines in indicators/stoch_rsi.rs (file at 92.37%): const accessors periods (69-71), value (74-76) and Indicator-impl name (131-133). stoch_rsi.rs now at 118/118. * test(tema): cover period accessor + warmup/name metadata Codecov flagged 9 lines in indicators/tema.rs (file at 83.63%): const accessor period (45-47), Indicator-impl warmup_period (67-69), name (75-77). tema.rs now at 55/55. * test(trima): cover period/value accessors + name metadata Codecov flagged 9 lines in indicators/trima.rs (file at 89.53%): const accessors period (59-61), value (64-66) and Indicator-impl name (99-101). trima.rs now at 86/86. --- crates/wickra-core/src/indicators/mom.rs | 15 +++++++++++++++ crates/wickra-core/src/indicators/sma.rs | 11 +++++++++++ crates/wickra-core/src/indicators/stoch_rsi.rs | 15 +++++++++++++++ crates/wickra-core/src/indicators/tema.rs | 12 ++++++++++++ crates/wickra-core/src/indicators/trima.rs | 15 +++++++++++++++ 5 files changed, 68 insertions(+) diff --git a/crates/wickra-core/src/indicators/mom.rs b/crates/wickra-core/src/indicators/mom.rs index 5c5da8ae..8ea529a2 100644 --- a/crates/wickra-core/src/indicators/mom.rs +++ b/crates/wickra-core/src/indicators/mom.rs @@ -114,6 +114,21 @@ mod tests { assert!(matches!(Mom::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessors `period` / `value` (56-63) and the + /// Indicator-impl `name` body (101-103). Existing tests inspect + /// momentum output but never query the metadata. + #[test] + fn accessors_and_metadata() { + let mut m = Mom::new(5).unwrap(); + assert_eq!(m.period(), 5); + assert_eq!(m.name(), "MOM"); + assert_eq!(m.value(), None); + for i in 1..=6 { + m.update(f64::from(i)); + } + assert!(m.value().is_some()); + } + #[test] fn reference_values() { // MOM(3): price_t − price_{t-3}. diff --git a/crates/wickra-core/src/indicators/sma.rs b/crates/wickra-core/src/indicators/sma.rs index 8e0ec828..f8ed8d55 100644 --- a/crates/wickra-core/src/indicators/sma.rs +++ b/crates/wickra-core/src/indicators/sma.rs @@ -136,6 +136,17 @@ mod tests { assert!(matches!(Sma::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessor `period` (70-72) and the Indicator-impl + /// `warmup_period` (115-117) + `name` (123-125). Existing tests + /// inspect SMA output but never query the metadata. + #[test] + fn accessors_and_metadata() { + let sma = Sma::new(20).unwrap(); + assert_eq!(sma.period(), 20); + assert_eq!(sma.warmup_period(), 20); + assert_eq!(sma.name(), "SMA"); + } + #[test] fn warmup_returns_none() { let mut sma = Sma::new(3).unwrap(); diff --git a/crates/wickra-core/src/indicators/stoch_rsi.rs b/crates/wickra-core/src/indicators/stoch_rsi.rs index 63d4c7c6..43e1d0ed 100644 --- a/crates/wickra-core/src/indicators/stoch_rsi.rs +++ b/crates/wickra-core/src/indicators/stoch_rsi.rs @@ -145,6 +145,21 @@ mod tests { assert!(matches!(StochRsi::new(14, 0), Err(Error::PeriodZero))); } + /// Cover the const accessors `periods` / `value` (69-76) and the + /// Indicator-impl `name` body (131-133). `warmup_period` is already + /// covered by `first_emission_at_warmup_period`. + #[test] + fn accessors_and_metadata() { + let mut sr = StochRsi::new(14, 14).unwrap(); + assert_eq!(sr.periods(), (14, 14)); + assert_eq!(sr.name(), "StochRSI"); + assert_eq!(sr.value(), None); + for i in 1..=sr.warmup_period() { + sr.update(100.0 + f64::from(u32::try_from(i).unwrap())); + } + assert!(sr.value().is_some()); + } + #[test] fn first_emission_at_warmup_period() { let mut sr = StochRsi::new(5, 4).unwrap(); diff --git a/crates/wickra-core/src/indicators/tema.rs b/crates/wickra-core/src/indicators/tema.rs index ef872f40..c3b996c6 100644 --- a/crates/wickra-core/src/indicators/tema.rs +++ b/crates/wickra-core/src/indicators/tema.rs @@ -117,4 +117,16 @@ mod tests { fn rejects_zero_period() { assert!(Tema::new(0).is_err()); } + + /// Cover the const accessor `period` (45-47) and the Indicator-impl + /// `warmup_period` (67-69) + `name` (75-77). Existing tests inspect + /// TEMA output but never query the metadata. + #[test] + fn accessors_and_metadata() { + let tema = Tema::new(5).unwrap(); + assert_eq!(tema.period(), 5); + // EMA1 seeds at period (5), each cascade stage needs another (period-1) inputs. + assert_eq!(tema.warmup_period(), 3 * 5 - 2); + assert_eq!(tema.name(), "TEMA"); + } } diff --git a/crates/wickra-core/src/indicators/trima.rs b/crates/wickra-core/src/indicators/trima.rs index 81b144c1..b7f7c11f 100644 --- a/crates/wickra-core/src/indicators/trima.rs +++ b/crates/wickra-core/src/indicators/trima.rs @@ -112,6 +112,21 @@ mod tests { assert!(matches!(Trima::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessors `period` / `value` (59-66) and the + /// Indicator-impl `name` body (99-101). Existing tests inspect + /// TRIMA output but never query the metadata. + #[test] + fn accessors_and_metadata() { + let mut t = Trima::new(5).unwrap(); + assert_eq!(t.period(), 5); + assert_eq!(t.name(), "TRIMA"); + assert_eq!(t.value(), None); + for i in 1..=t.warmup_period() { + t.update(f64::from(u32::try_from(i).unwrap())); + } + assert!(t.value().is_some()); + } + #[test] fn odd_period_reference_values() { // TRIMA(5) is SMA(3) of SMA(3).