From 512bbf75c4beb329393246f8e6d40a6b039dbaeb Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sun, 24 May 2026 00:47:59 +0200 Subject: [PATCH] test: 100% coverage for keltner + linreg + linreg_slope + macd + super_trend (#30) * test(keltner): cover periods accessor + name metadata Codecov flagged 6 lines (file at 95.23%): periods (68-70) + name (106-108). * test(linreg): cover period accessor + name metadata Codecov flagged 6 lines (file at 96.10%): period (92-94) + name (142-144). * test(linreg_slope): cover period accessor + name metadata Codecov flagged 6 lines (file at 95.91%): period (80-82) + name (125-127). * test(macd): cover periods/value accessors + name metadata Codecov flagged 6 lines (file at 95.45%): periods (81-83) + name (135-137). * test(super_trend): cover params accessor + name metadata Codecov flagged 6 lines (file at 96.36%): params (99-101) + name (176-178). --- crates/wickra-core/src/indicators/keltner.rs | 13 +++++++++++++ crates/wickra-core/src/indicators/linreg.rs | 9 +++++++++ crates/wickra-core/src/indicators/linreg_slope.rs | 9 +++++++++ crates/wickra-core/src/indicators/macd.rs | 15 +++++++++++++++ crates/wickra-core/src/indicators/super_trend.rs | 11 +++++++++++ 5 files changed, 57 insertions(+) diff --git a/crates/wickra-core/src/indicators/keltner.rs b/crates/wickra-core/src/indicators/keltner.rs index ebf5e5ba..7c7bac0a 100644 --- a/crates/wickra-core/src/indicators/keltner.rs +++ b/crates/wickra-core/src/indicators/keltner.rs @@ -162,6 +162,19 @@ mod tests { assert!(Keltner::new(20, 10, -1.0).is_err()); } + /// Cover the const accessor `periods` (68-70) and the Indicator-impl + /// `name` body (106-108). Existing tests inspect band output but + /// never query the metadata. + #[test] + fn accessors_and_metadata() { + let k = Keltner::new(20, 10, 2.0).unwrap(); + let (ema, atr, mult) = k.periods(); + assert_eq!(ema, 20); + assert_eq!(atr, 10); + assert!((mult - 2.0).abs() < 1e-12); + assert_eq!(k.name(), "KeltnerChannels"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..50) diff --git a/crates/wickra-core/src/indicators/linreg.rs b/crates/wickra-core/src/indicators/linreg.rs index 2795ba30..df174120 100644 --- a/crates/wickra-core/src/indicators/linreg.rs +++ b/crates/wickra-core/src/indicators/linreg.rs @@ -199,6 +199,15 @@ mod tests { assert!(LinearRegression::new(2).is_ok()); } + /// Cover the const accessor `period` (92-94) and the Indicator-impl + /// `name` body (142-144). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let lr = LinearRegression::new(14).unwrap(); + assert_eq!(lr.period(), 14); + assert_eq!(lr.name(), "LinearRegression"); + } + #[test] fn reset_clears_state() { let mut lr = LinearRegression::new(5).unwrap(); diff --git a/crates/wickra-core/src/indicators/linreg_slope.rs b/crates/wickra-core/src/indicators/linreg_slope.rs index aab13211..0158da8e 100644 --- a/crates/wickra-core/src/indicators/linreg_slope.rs +++ b/crates/wickra-core/src/indicators/linreg_slope.rs @@ -188,6 +188,15 @@ mod tests { assert!(LinRegSlope::new(2).is_ok()); } + /// Cover the const accessor `period` (80-82) and the Indicator-impl + /// `name` body (125-127). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let ls = LinRegSlope::new(14).unwrap(); + assert_eq!(ls.period(), 14); + assert_eq!(ls.name(), "LinRegSlope"); + } + #[test] fn reset_clears_state() { let mut ls = LinRegSlope::new(5).unwrap(); diff --git a/crates/wickra-core/src/indicators/macd.rs b/crates/wickra-core/src/indicators/macd.rs index 1d6e821f..04346bca 100644 --- a/crates/wickra-core/src/indicators/macd.rs +++ b/crates/wickra-core/src/indicators/macd.rs @@ -155,6 +155,21 @@ mod tests { )); } + /// Cover the const accessors `periods` / `value` (81-88) and the + /// Indicator-impl `name` body (135-137). `warmup_period` is exercised + /// elsewhere. + #[test] + fn accessors_and_metadata() { + let mut m = MacdIndicator::new(12, 26, 9).unwrap(); + assert_eq!(m.periods(), (12, 26, 9)); + assert_eq!(m.name(), "MACD"); + assert!(m.value().is_none()); + for i in 1..=m.warmup_period() { + m.update(100.0 + f64::from(u32::try_from(i).unwrap())); + } + assert!(m.value().is_some()); + } + #[test] fn rejects_zero_periods() { assert!(matches!( diff --git a/crates/wickra-core/src/indicators/super_trend.rs b/crates/wickra-core/src/indicators/super_trend.rs index e9a2a7de..50374249 100644 --- a/crates/wickra-core/src/indicators/super_trend.rs +++ b/crates/wickra-core/src/indicators/super_trend.rs @@ -281,6 +281,17 @@ mod tests { assert!(SuperTrend::new(10, f64::NAN).is_err()); } + /// Cover the const accessor `params` (99-101) and the Indicator-impl + /// `name` body (176-178). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let st = SuperTrend::new(10, 3.0).unwrap(); + let (p, m) = st.params(); + assert_eq!(p, 10); + assert!((m - 3.0).abs() < 1e-12); + assert_eq!(st.name(), "SuperTrend"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..40)