From 6969541bb1809ce161d983e3e6d2b9caa7cb61a4 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sat, 23 May 2026 23:39:32 +0200 Subject: [PATCH] test(stochastic): cover classic/periods/metadata + naive_k flat branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codecov flagged 13 uncovered lines in crates/wickra-core/src/indicators/stochastic.rs (file at 93.43%): - classic() convenience constructor (76-78) — every test passed explicit (k_period, d_period) to new - periods() const accessor (81-83) — never queried - warmup_period (170-172), name (178-180) Indicator-impl bodies — never queried - line 208 (`50.0` literal) inside the test-only naive_k helper's flat-range branch — k_matches_naive feeds an oscillating price series, so the helper's range == 0 path was dead Add classic_periods_and_metadata test asserting Stochastic::classic() has periods (14, 3), warmup_period 16 (= 14 + 3 - 1) and name "Stochastic". Extend flat_range_yields_k_50 to also call naive_k on the flat candle series and verify the helper returns Some(50.0) for every index ≥ k_period - 1 — exercises line 208 without diluting the production-code assertion. stochastic.rs is now at 198/198 lines, no behavioural change. --- .../wickra-core/src/indicators/stochastic.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/wickra-core/src/indicators/stochastic.rs b/crates/wickra-core/src/indicators/stochastic.rs index 9df886ba..79865954 100644 --- a/crates/wickra-core/src/indicators/stochastic.rs +++ b/crates/wickra-core/src/indicators/stochastic.rs @@ -220,6 +220,20 @@ mod tests { assert!(matches!(Stochastic::new(14, 0), Err(Error::PeriodZero))); } + /// Cover the `Stochastic::classic()` convenience constructor plus the + /// `periods()` const accessor and the Indicator-impl `warmup_period` + /// / `name` methods. Existing tests called `Stochastic::new(_, _)` + /// directly and never asked for the configured periods, warmup + /// length, or name. + #[test] + fn classic_periods_and_metadata() { + let s = Stochastic::classic(); + assert_eq!(s.periods(), (14, 3)); + // Warmup for the classic config: k_period + d_period - 1 = 14 + 3 - 1 = 16. + assert_eq!(s.warmup_period(), 16); + assert_eq!(s.name(), "Stochastic"); + } + #[test] fn close_at_high_yields_k_100() { let candles = vec![ @@ -252,6 +266,13 @@ mod tests { assert_relative_eq!(o.k, 50.0, epsilon = 1e-12); assert_relative_eq!(o.d, 50.0, epsilon = 1e-12); } + // Cross-check: the naive_k test helper must agree on the flat-range + // convention. The k_matches_naive test only feeds oscillating prices, + // so the helper's flat-range branch was never exercised. + let ks = naive_k(&candles, 14); + for k in ks.into_iter().skip(13) { + assert_relative_eq!(k.expect("ready after 14 inputs"), 50.0, epsilon = 1e-12); + } } #[test]