From 863d36bc87c20280f06ffca51adafc5c9a8ab38e Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Sat, 11 Nov 2023 11:12:21 +0100 Subject: [PATCH] Fix incorrect test simplification. In https://github.com/HdrHistogram/HdrHistogram_rust/pull/125#discussion_r1390185430 a simplification was made without discussion: ```diff - h.iter_recorded().collect::>().len() + h.iter_recorded().count() ``` This is incorrect as what this test actually tests was that the iterator has the correct length. In a perfect world both should be identical but the PR fix a case where this was not the case as some items would be skipped over. In this I revert the change, add a comment and a second (redundant) check to make sure this is not re-simplified later. --- tests/histogram.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/histogram.rs b/tests/histogram.rs index d4e3f38..7f09798 100644 --- a/tests/histogram.rs +++ b/tests/histogram.rs @@ -565,5 +565,12 @@ fn subtract_underflow_guarded_by_per_value_count_check() { fn recorded_only_zeros() { let mut h = Histogram::::new(1).unwrap(); h += 0; - assert_eq!(h.iter_recorded().count(), 1); + // Do not simplify .collect::>().len() to .count() + // This check a bug where .count() and .collect::>().len() + // are different + assert_eq!(h.iter_recorded().collect::>().len(), 1); + assert_eq!( + h.iter_recorded().collect::>().len(), + h.iter_recorded().count() + ); }