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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user