test: 100% coverage for tsi + ultimate_oscillator + vortex + vwma + zlema (#26)
* test(tsi): cover periods/value accessors + name metadata Codecov flagged 9 lines in indicators/tsi.rs (file at 92.30%): const accessors periods (70-72), value (75-77) and Indicator-impl name (137-139). tsi.rs now at 117/117. * test(ultimate_oscillator): cover periods/value accessors + name metadata Codecov flagged 9 lines in indicators/ultimate_oscillator.rs (file at 94.76%): const accessors periods (96-98), value (101-103) and Indicator-impl name (193-195). uo.rs now at 172/172. * test(vortex): cover period/value accessors + name metadata Codecov flagged 9 lines in indicators/vortex.rs (file at 93.18%): const accessors period (84-86), value (89-91) and Indicator-impl name (157-159). vortex.rs now at 132/132. * test(vwma): cover period/value accessors + name metadata Codecov flagged 9 lines in indicators/vwma.rs (file at 92.56%): const accessors period (72-74), value (77-79) and Indicator-impl name (129-131). vwma.rs now at 121/121. * test(zlema): cover period/value accessors + name metadata Codecov flagged 9 lines in indicators/zlema.rs (file at 90.62%): const accessors period (62-64), value (72-74) and Indicator-impl name (111-113). zlema.rs now at 96/96.
This commit is contained in:
@@ -151,6 +151,21 @@ mod tests {
|
||||
assert!(matches!(Tsi::new(25, 0), Err(Error::PeriodZero)));
|
||||
}
|
||||
|
||||
/// Cover the const accessors `periods` / `value` (70-77) and the
|
||||
/// Indicator-impl `name` body (137-139). Existing tests inspect
|
||||
/// TSI output but never query the metadata.
|
||||
#[test]
|
||||
fn accessors_and_metadata() {
|
||||
let mut tsi = Tsi::new(25, 13).unwrap();
|
||||
assert_eq!(tsi.periods(), (25, 13));
|
||||
assert_eq!(tsi.name(), "TSI");
|
||||
assert_eq!(tsi.value(), None);
|
||||
for i in 1..=tsi.warmup_period() {
|
||||
tsi.update(100.0 + f64::from(u32::try_from(i).unwrap()));
|
||||
}
|
||||
assert!(tsi.value().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_emission_at_warmup_period() {
|
||||
let mut tsi = Tsi::new(5, 3).unwrap();
|
||||
|
||||
@@ -222,6 +222,28 @@ mod tests {
|
||||
));
|
||||
}
|
||||
|
||||
/// Cover the const accessors `periods` / `value` (96-103) and the
|
||||
/// Indicator-impl `name` body (193-195). `warmup_period` is covered
|
||||
/// by `first_emission_at_warmup_period`.
|
||||
#[test]
|
||||
fn accessors_and_metadata() {
|
||||
let mut uo = UltimateOscillator::new(7, 14, 28).unwrap();
|
||||
assert_eq!(uo.periods(), (7, 14, 28));
|
||||
assert_eq!(uo.name(), "UltimateOscillator");
|
||||
assert_eq!(uo.value(), None);
|
||||
let warmup = i64::try_from(uo.warmup_period()).unwrap();
|
||||
let candles: Vec<Candle> = (0..warmup)
|
||||
.map(|i| {
|
||||
let p = 100.0 + (i as f64 * 0.3).sin() * 5.0;
|
||||
Candle::new(p, p + 1.0, p - 1.0, p, 1.0, i).unwrap()
|
||||
})
|
||||
.collect();
|
||||
for c in &candles {
|
||||
uo.update(*c);
|
||||
}
|
||||
assert!(uo.value().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first_emission_at_warmup_period() {
|
||||
let mut uo = UltimateOscillator::new(2, 3, 5).unwrap();
|
||||
|
||||
@@ -174,6 +174,28 @@ mod tests {
|
||||
assert!(matches!(Vortex::new(0), Err(Error::PeriodZero)));
|
||||
}
|
||||
|
||||
/// Cover the const accessors `period` / `value` (84-91) and the
|
||||
/// Indicator-impl `name` body (157-159). `warmup_period` is covered
|
||||
/// elsewhere.
|
||||
#[test]
|
||||
fn accessors_and_metadata() {
|
||||
let mut v = Vortex::new(14).unwrap();
|
||||
assert_eq!(v.period(), 14);
|
||||
assert_eq!(v.name(), "Vortex");
|
||||
assert!(v.value().is_none());
|
||||
let warmup = i64::try_from(v.warmup_period()).unwrap();
|
||||
let candles: Vec<Candle> = (0..warmup)
|
||||
.map(|i| {
|
||||
let p = 100.0 + (i as f64 * 0.3).sin() * 5.0;
|
||||
Candle::new(p, p + 1.0, p - 1.0, p, 1.0, i).unwrap()
|
||||
})
|
||||
.collect();
|
||||
for c in &candles {
|
||||
v.update(*c);
|
||||
}
|
||||
assert!(v.value().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_values() {
|
||||
// Vortex(2) over three explicit candles (high, low, close):
|
||||
|
||||
@@ -147,6 +147,22 @@ mod tests {
|
||||
assert!(matches!(Vwma::new(0), Err(Error::PeriodZero)));
|
||||
}
|
||||
|
||||
/// Cover the const accessors `period` / `value` (72-79) and the
|
||||
/// Indicator-impl `name` body (129-131). Existing tests inspect
|
||||
/// VWMA output but never query the metadata.
|
||||
#[test]
|
||||
fn accessors_and_metadata() {
|
||||
let mut v = Vwma::new(5).unwrap();
|
||||
assert_eq!(v.period(), 5);
|
||||
assert_eq!(v.name(), "VWMA");
|
||||
assert_eq!(v.value(), None);
|
||||
for i in 1..=5i64 {
|
||||
let p = 100.0 + i as f64;
|
||||
v.update(Candle::new(p, p, p, p, 1.0, i).unwrap());
|
||||
}
|
||||
assert!(v.value().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reference_value() {
|
||||
// VWMA(2): (10·1 + 20·3) / (1 + 3) = 70 / 4 = 17.5.
|
||||
|
||||
@@ -124,6 +124,21 @@ mod tests {
|
||||
assert!(matches!(Zlema::new(0), Err(Error::PeriodZero)));
|
||||
}
|
||||
|
||||
/// Cover the const accessors `period` / `value` (62-64, 72-74) and
|
||||
/// the Indicator-impl `name` body (111-113). `lag` is already covered
|
||||
/// by `lag_is_half_of_period_minus_one`.
|
||||
#[test]
|
||||
fn accessors_and_metadata() {
|
||||
let mut z = Zlema::new(5).unwrap();
|
||||
assert_eq!(z.period(), 5);
|
||||
assert_eq!(z.name(), "ZLEMA");
|
||||
assert_eq!(z.value(), None);
|
||||
for i in 1..=z.warmup_period() {
|
||||
z.update(f64::from(u32::try_from(i).unwrap()));
|
||||
}
|
||||
assert!(z.value().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lag_is_half_of_period_minus_one() {
|
||||
assert_eq!(Zlema::new(3).unwrap().lag(), 1);
|
||||
|
||||
Reference in New Issue
Block a user