test: 100% coverage for mom + sma + stoch_rsi + tema + trima (#25)

* test(mom): cover period/value accessors + name metadata

Codecov flagged 9 lines in indicators/mom.rs (file at 89.53%): const
accessors period (56-58), value (61-63) and Indicator-impl name
(101-103). mom.rs now at 86/86.

* test(sma): cover period accessor + warmup/name metadata

Codecov flagged 9 lines in indicators/sma.rs (file at 93.12%): const
accessor period (70-72), Indicator-impl warmup_period (115-117),
name (123-125). sma.rs now at 131/131.

* test(stoch_rsi): cover periods/value accessors + name metadata

Codecov flagged 9 lines in indicators/stoch_rsi.rs (file at 92.37%):
const accessors periods (69-71), value (74-76) and Indicator-impl
name (131-133). stoch_rsi.rs now at 118/118.

* test(tema): cover period accessor + warmup/name metadata

Codecov flagged 9 lines in indicators/tema.rs (file at 83.63%): const
accessor period (45-47), Indicator-impl warmup_period (67-69), name
(75-77). tema.rs now at 55/55.

* test(trima): cover period/value accessors + name metadata

Codecov flagged 9 lines in indicators/trima.rs (file at 89.53%): const
accessors period (59-61), value (64-66) and Indicator-impl name
(99-101). trima.rs now at 86/86.
This commit is contained in:
kingchenc
2026-05-24 00:47:43 +02:00
committed by GitHub
parent 5a6689cf1a
commit 645b002958
5 changed files with 68 additions and 0 deletions
+15
View File
@@ -114,6 +114,21 @@ mod tests {
assert!(matches!(Mom::new(0), Err(Error::PeriodZero)));
}
/// Cover the const accessors `period` / `value` (56-63) and the
/// Indicator-impl `name` body (101-103). Existing tests inspect
/// momentum output but never query the metadata.
#[test]
fn accessors_and_metadata() {
let mut m = Mom::new(5).unwrap();
assert_eq!(m.period(), 5);
assert_eq!(m.name(), "MOM");
assert_eq!(m.value(), None);
for i in 1..=6 {
m.update(f64::from(i));
}
assert!(m.value().is_some());
}
#[test]
fn reference_values() {
// MOM(3): price_t price_{t-3}.
+11
View File
@@ -136,6 +136,17 @@ mod tests {
assert!(matches!(Sma::new(0), Err(Error::PeriodZero)));
}
/// Cover the const accessor `period` (70-72) and the Indicator-impl
/// `warmup_period` (115-117) + `name` (123-125). Existing tests
/// inspect SMA output but never query the metadata.
#[test]
fn accessors_and_metadata() {
let sma = Sma::new(20).unwrap();
assert_eq!(sma.period(), 20);
assert_eq!(sma.warmup_period(), 20);
assert_eq!(sma.name(), "SMA");
}
#[test]
fn warmup_returns_none() {
let mut sma = Sma::new(3).unwrap();
@@ -145,6 +145,21 @@ mod tests {
assert!(matches!(StochRsi::new(14, 0), Err(Error::PeriodZero)));
}
/// Cover the const accessors `periods` / `value` (69-76) and the
/// Indicator-impl `name` body (131-133). `warmup_period` is already
/// covered by `first_emission_at_warmup_period`.
#[test]
fn accessors_and_metadata() {
let mut sr = StochRsi::new(14, 14).unwrap();
assert_eq!(sr.periods(), (14, 14));
assert_eq!(sr.name(), "StochRSI");
assert_eq!(sr.value(), None);
for i in 1..=sr.warmup_period() {
sr.update(100.0 + f64::from(u32::try_from(i).unwrap()));
}
assert!(sr.value().is_some());
}
#[test]
fn first_emission_at_warmup_period() {
let mut sr = StochRsi::new(5, 4).unwrap();
+12
View File
@@ -117,4 +117,16 @@ mod tests {
fn rejects_zero_period() {
assert!(Tema::new(0).is_err());
}
/// Cover the const accessor `period` (45-47) and the Indicator-impl
/// `warmup_period` (67-69) + `name` (75-77). Existing tests inspect
/// TEMA output but never query the metadata.
#[test]
fn accessors_and_metadata() {
let tema = Tema::new(5).unwrap();
assert_eq!(tema.period(), 5);
// EMA1 seeds at period (5), each cascade stage needs another (period-1) inputs.
assert_eq!(tema.warmup_period(), 3 * 5 - 2);
assert_eq!(tema.name(), "TEMA");
}
}
@@ -112,6 +112,21 @@ mod tests {
assert!(matches!(Trima::new(0), Err(Error::PeriodZero)));
}
/// Cover the const accessors `period` / `value` (59-66) and the
/// Indicator-impl `name` body (99-101). Existing tests inspect
/// TRIMA output but never query the metadata.
#[test]
fn accessors_and_metadata() {
let mut t = Trima::new(5).unwrap();
assert_eq!(t.period(), 5);
assert_eq!(t.name(), "TRIMA");
assert_eq!(t.value(), None);
for i in 1..=t.warmup_period() {
t.update(f64::from(u32::try_from(i).unwrap()));
}
assert!(t.value().is_some());
}
#[test]
fn odd_period_reference_values() {
// TRIMA(5) is SMA(3) of SMA(3).