test: 100% coverage for rsi + accelerator_oscillator + aroon + atr_trailing_stop + chaikin_oscillator (#28)

* 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.
This commit is contained in:
kingchenc
2026-05-24 00:47:53 +02:00
committed by GitHub
parent c7f1e14629
commit d9a1950007
5 changed files with 67 additions and 0 deletions
@@ -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<Candle> = (0..60).map(|i| c(11.0, 9.0, 10.0, i)).collect();
@@ -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");
}
}
@@ -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<Candle> = (0..40)
@@ -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<Candle> = (0..40).map(|i| cdl(100.0 + i as f64, 50.0, i)).collect();
+28
View File
@@ -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();