test: 100% coverage for vertical_horizontal_filter + z_score + vpt + csv + adl (#31)

* test(vertical_horizontal_filter): cover period accessor + name metadata

Codecov flagged 6 lines (file at 94.44%): period (61-63) + name (119-121).

* test(z_score): cover period accessor + name metadata

Codecov flagged 6 lines (file at 93.75%): period (59-61) + name (106-108).

* test(vpt): cover value() Some branch, name, zero-prev fallback

Codecov flagged 5 lines (file at 94.38%): value() Some branch (57),
prev==0.0 ROC fallback (77), and Indicator-impl name (100-102).
Add accessors_and_metadata covering value()/name and zero_previous_
close_contributes_zero — feeding a 0.0 baseline + non-zero candle
proves the divide-by-zero guard yields a 0 contribution rather than NaN.

* test(csv): cover from_csv_reader + kill rejects_header dead panic arm

Codecov flagged 5 lines in csv.rs (file at 96.98%): from_csv_reader
(201-204) — never called by existing tests which use from_reader /
open — and the cold  arm in
rejects_header_missing_a_column (279). Add from_csv_reader_accepts_a_
prebuilt_reader (demonstrates the API by building a custom-delimited
csv::Reader and passing it in), and refactor the header-missing test
to use a single matches!() assertion so the panic arm is gone.

* test(adl): cover name metadata

Codecov flagged 3 lines (file at 96.84%): Indicator-impl name body (94-96).
This commit is contained in:
kingchenc
2026-05-24 00:48:02 +02:00
committed by GitHub
parent 512bbf75c4
commit d55d3db3d1
5 changed files with 74 additions and 4 deletions
+24 -4
View File
@@ -274,10 +274,30 @@ mod tests {
// "volume" is absent.
let data = "timestamp,open,high,low,close\n1,10.0,11.0,9.0,10.5\n";
let err = CandleReader::from_reader(data.as_bytes()).unwrap_err();
match err {
Error::Malformed(msg) => assert!(msg.contains("volume"), "msg: {msg}"),
other => panic!("expected Malformed, got {other:?}"),
}
// The error variant must be Malformed and the message must mention
// the missing column. Asserting directly (rather than match-and-
// panic-on-other) keeps the assertion's cold path branch-free for
// coverage and still pins the diagnostic.
assert!(
matches!(&err, Error::Malformed(msg) if msg.contains("volume")),
"expected Malformed mentioning 'volume', got {err:?}"
);
}
/// Cover `from_csv_reader` (lines 201-204): existing tests use
/// `from_reader` / `open`, which both construct the inner `csv::Reader`
/// internally. Callers that want non-default csv configuration must
/// build the reader themselves and pass it through `from_csv_reader`.
#[test]
fn from_csv_reader_accepts_a_prebuilt_reader() {
let data = "timestamp;open;high;low;close;volume\n1;10.0;11.0;9.0;10.5;100\n";
let inner = csv::ReaderBuilder::new()
.delimiter(b';')
.from_reader(data.as_bytes());
let mut r = CandleReader::from_csv_reader(inner).unwrap();
let candles = r.read_all().unwrap();
assert_eq!(candles.len(), 1);
assert_eq!(candles[0].close, 10.5);
}
#[test]