From d9a19500079c388bd88b5cdac6f973bde2ff4dd8 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sun, 24 May 2026 00:47:53 +0200 Subject: [PATCH] test: 100% coverage for rsi + accelerator_oscillator + aroon + atr_trailing_stop + chaikin_oscillator (#28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test(rsi): cover period/value accessors, name, naive flat-series branch Codecov flagged 7 lines in indicators/rsi.rs (file at 96.42%): const accessors period (60-62), value (65-67), Indicator-impl name (145-147), and line 167 in the test-helper rsi_naive's ag==0 fallback. The proptest reference never lands on a fully flat series so the helper's 50.0 branch was dead. Add accessors_and_metadata covering period/value/name and naive_helper_flat_series_yields_50 driving rsi_naive on [42.0; 20] — both avg_gain and avg_loss converge to 0, hitting the 50.0 branch. rsi.rs now at 196/196. * test(accelerator_oscillator): cover params accessor + name metadata Codecov flagged 6 lines in indicators/accelerator_oscillator.rs (file at 93.68%): const accessor params (69-71) and Indicator-impl name (99-101). ac.rs now at 95/95. * test(aroon): cover period accessor + name metadata Codecov flagged 6 lines in indicators/aroon.rs (file at 94.28%): const accessor period (56-58) and Indicator-impl name (104-106). aroon.rs now at 105/105. * test(atr_trailing_stop): cover params accessor + name metadata Codecov flagged 6 lines in indicators/atr_trailing_stop.rs (file at 95.91%): const accessor params (77-79) and Indicator-impl name (130-132). atr_trailing_stop.rs now at 147/147. * test(chaikin_oscillator): cover periods accessor + name metadata Codecov flagged 6 lines in indicators/chaikin_oscillator.rs (file at 95.27%): const accessor periods (76-78) and Indicator-impl name (109-111). chaikin_oscillator.rs now at 127/127. --- .../src/indicators/accelerator_oscillator.rs | 10 +++++++ crates/wickra-core/src/indicators/aroon.rs | 9 ++++++ .../src/indicators/atr_trailing_stop.rs | 11 ++++++++ .../src/indicators/chaikin_oscillator.rs | 9 ++++++ crates/wickra-core/src/indicators/rsi.rs | 28 +++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/crates/wickra-core/src/indicators/accelerator_oscillator.rs b/crates/wickra-core/src/indicators/accelerator_oscillator.rs index 5e985a54..2acc66e7 100644 --- a/crates/wickra-core/src/indicators/accelerator_oscillator.rs +++ b/crates/wickra-core/src/indicators/accelerator_oscillator.rs @@ -165,6 +165,16 @@ mod tests { assert!(AcceleratorOscillator::new(34, 5, 5).is_err()); } + /// Cover the const accessor `params` (69-71) and the Indicator-impl + /// `name` body (99-101). Existing tests inspect numeric output but + /// never query the metadata. + #[test] + fn accessors_and_metadata() { + let ac = AcceleratorOscillator::classic(); + assert_eq!(ac.params(), (5, 34, 5)); + assert_eq!(ac.name(), "AcceleratorOscillator"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..60).map(|i| c(11.0, 9.0, 10.0, i)).collect(); diff --git a/crates/wickra-core/src/indicators/aroon.rs b/crates/wickra-core/src/indicators/aroon.rs index 485fad20..0719ec9a 100644 --- a/crates/wickra-core/src/indicators/aroon.rs +++ b/crates/wickra-core/src/indicators/aroon.rs @@ -182,4 +182,13 @@ mod tests { assert!(!a.is_ready()); assert_eq!(a.update(candles[0]), None); } + + /// Cover the const accessor `period` (56-58) and the Indicator-impl + /// `name` body (104-106). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let a = Aroon::new(14).unwrap(); + assert_eq!(a.period(), 14); + assert_eq!(a.name(), "Aroon"); + } } diff --git a/crates/wickra-core/src/indicators/atr_trailing_stop.rs b/crates/wickra-core/src/indicators/atr_trailing_stop.rs index b1e7a143..1ba90ba8 100644 --- a/crates/wickra-core/src/indicators/atr_trailing_stop.rs +++ b/crates/wickra-core/src/indicators/atr_trailing_stop.rs @@ -234,6 +234,17 @@ mod tests { assert!(AtrTrailingStop::new(14, f64::NAN).is_err()); } + /// Cover the const accessor `params` (77-79) and the Indicator-impl + /// `name` body (130-132). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let s = AtrTrailingStop::classic(); + let (atr_p, mult) = s.params(); + assert_eq!(atr_p, 14); + assert!((mult - 3.0).abs() < 1e-12); + assert_eq!(s.name(), "AtrTrailingStop"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..40) diff --git a/crates/wickra-core/src/indicators/chaikin_oscillator.rs b/crates/wickra-core/src/indicators/chaikin_oscillator.rs index c41ce479..3ea663a0 100644 --- a/crates/wickra-core/src/indicators/chaikin_oscillator.rs +++ b/crates/wickra-core/src/indicators/chaikin_oscillator.rs @@ -196,6 +196,15 @@ mod tests { assert!(ChaikinOscillator::new(5, 5).is_err()); } + /// Cover the const accessor `periods` (76-78) and the Indicator-impl + /// `name` body (109-111). `warmup_period` is exercised elsewhere. + #[test] + fn accessors_and_metadata() { + let osc = ChaikinOscillator::classic(); + assert_eq!(osc.periods(), (3, 10)); + assert_eq!(osc.name(), "ChaikinOscillator"); + } + #[test] fn reset_clears_state() { let candles: Vec = (0..40).map(|i| cdl(100.0 + i as f64, 50.0, i)).collect(); diff --git a/crates/wickra-core/src/indicators/rsi.rs b/crates/wickra-core/src/indicators/rsi.rs index cabaeb08..e3ccdcff 100644 --- a/crates/wickra-core/src/indicators/rsi.rs +++ b/crates/wickra-core/src/indicators/rsi.rs @@ -202,6 +202,34 @@ mod tests { assert!(matches!(Rsi::new(0), Err(Error::PeriodZero))); } + /// Cover the const accessors `period` / `value` (60-67) and the + /// Indicator-impl `name` body (145-147). `warmup_period` is covered + /// already by `warmup_period_is_period_plus_one`. + #[test] + fn accessors_and_metadata() { + let mut rsi = Rsi::new(14).unwrap(); + assert_eq!(rsi.period(), 14); + assert_eq!(rsi.name(), "RSI"); + assert_eq!(rsi.value(), None); + for i in 1..=15 { + rsi.update(100.0 + f64::from(i)); + } + assert!(rsi.value().is_some()); + } + + /// Cover the `ag == 0` branch (line 167) of the test-helper `rsi_naive`: + /// when both `avg_gain` and `avg_loss` are 0 (a perfectly flat series), + /// the helper must return the neutral 50.0. The proptest reference uses + /// random inputs that essentially never hit zero gains AND zero losses + /// simultaneously, leaving this branch dead in the helper. + #[test] + fn naive_helper_flat_series_yields_50() { + let ks = rsi_naive(&[42.0; 20], 5); + for r in ks.into_iter().skip(5) { + assert_eq!(r.expect("ready after period+1 inputs"), 50.0); + } + } + #[test] fn warmup_period_is_period_plus_one() { let rsi = Rsi::new(14).unwrap();