From 62fe7a81aa634f2f19d710dc485a61c17a6715b6 Mon Sep 17 00:00:00 2001 From: kingchenc Date: Sat, 23 May 2026 23:19:24 +0200 Subject: [PATCH] test(traits): cover Chain accessors + Identity/Doubler helper surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codecov flagged 30 uncovered lines in crates/wickra-core/src/traits.rs (file at 75.60%): the const borrow accessors Chain::first / Chain::second (140-147), the Chain::warmup_period + Chain::name Indicator-impl bodies (167-178), the full Identity test-helper Indicator surface — reset, warmup_period, is_ready, name (198-209), and Doubler's warmup_period + name (228-236). None of the existing tests touched those code paths: every chain test invoked update/reset/is_ready through the Chain wrapper without ever inspecting the borrow accessors, querying chain.warmup_period(), or asking for chain.name(), and the Identity helper was only ever driven by batch (which calls update only). Doubler's warmup_period and name were similarly dead because Chain::warmup_period and Chain::name themselves were dead. Add two new tests at the end of the Chain section in mod tests, immediately before the parallel-feature-gated test: - chain_accessors_and_metadata exercises chain.first(), chain.second(), chain.warmup_period(), chain.name(), and pulls Doubler::warmup_period + Doubler::name in via the borrowed accessors. - identity_helper_full_indicator_surface asserts warmup_period == 0, name == "Identity", and walks is_ready through both seen=false and seen=true via an update/reset cycle. traits.rs is now at 123/123 lines, no behavioural change. --- crates/wickra-core/src/traits.rs | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/crates/wickra-core/src/traits.rs b/crates/wickra-core/src/traits.rs index 8ea88328..3ccba7d2 100644 --- a/crates/wickra-core/src/traits.rs +++ b/crates/wickra-core/src/traits.rs @@ -275,6 +275,54 @@ mod tests { assert_eq!(c.update(1.0), Some(8.0)); } + /// Cover the `Chain::first` / `Chain::second` borrow accessors and the + /// `Chain::warmup_period` + `Chain::name` Indicator-impl bodies. + /// + /// Existing chain tests only invoked the Indicator surface (`update`, + /// `reset`, `is_ready`) on the wrapped `Chain`. The const borrow accessors + /// and the `warmup_period` / `name` impls were never traversed, so Codecov + /// flagged traits.rs lines 140-142, 145-147, 167-170, 176-178 as missed. + /// `chain.warmup_period()` also reaches `Doubler::warmup_period` + /// (228-230), and `chain.first().name()` reaches `Doubler::name` + /// (234-236) — both helper methods were uncovered for the same reason. + #[test] + fn chain_accessors_and_metadata() { + let chain = Chain::new(Doubler::default(), Doubler::default()); + // Borrow accessors return the wrapped stages; query each via .name() + // so Doubler::name (lines 234-236) is also exercised. + assert_eq!(chain.first().name(), "Doubler"); + assert_eq!(chain.second().name(), "Doubler"); + // Doubler::warmup_period (lines 228-230) is 0; Chain::warmup_period + // sums the two, so the result must also be 0. + assert_eq!(chain.first().warmup_period(), 0); + assert_eq!(chain.second().warmup_period(), 0); + assert_eq!(chain.warmup_period(), 0); + // Chain::name returns the literal "Chain" (line 177). + assert_eq!(chain.name(), "Chain"); + } + + /// Cover the full Indicator surface of the `Identity` test helper: + /// `reset` (198-200), `warmup_period` (201-203), `is_ready` (204-206), + /// and `name` (207-209). The only other test using `Identity` + /// (`batch_replays_update`) calls `batch`, which exercises `update` + /// alone, leaving the remaining four trait methods uncovered. + #[test] + fn identity_helper_full_indicator_surface() { + let mut id = Identity::default(); + // warmup_period is the literal 0; name is the literal "Identity". + assert_eq!(id.warmup_period(), 0); + assert_eq!(id.name(), "Identity"); + // is_ready exercises the `self.seen` return with seen=false first… + assert!(!id.is_ready()); + // …then with seen=true after a single update. + let out = id.update(42.0); + assert_eq!(out, Some(42.0)); + assert!(id.is_ready()); + // reset() flips seen back to false; is_ready reflects it. + id.reset(); + assert!(!id.is_ready()); + } + #[cfg(feature = "parallel")] #[test] fn batch_parallel_runs_independent_instances() {