From b5eab1d0b71a72a88fc2b4bcae9be38fc4b014b0 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Fri, 2 Feb 2024 13:37:55 -0500 Subject: [PATCH] test: check for unsorted iteration (#183) --- src/range.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/range.rs b/src/range.rs index ab88a0ca..1e8256cd 100644 --- a/src/range.rs +++ b/src/range.rs @@ -222,7 +222,17 @@ impl Range { I: Iterator + 's, V: 's, { + #[cfg(debug_assertions)] + let mut last: Option<&V> = None; versions.scan(0, move |i, v| { + #[cfg(debug_assertions)] + { + assert!( + last <= Some(v), + "`contains_many` `versions` argument incorrectly sorted" + ); + last = Some(v); + } while let Some(segment) = self.segments.get(*i) { match within_bounds(v, segment) { Ordering::Less => return Some(false), @@ -430,8 +440,18 @@ impl Range { I: Iterator + 'v, V: 'v, { + #[cfg(debug_assertions)] + let mut last: Option<&V> = None; // Return the segment index in the range for each version in the range, None otherwise let version_locations = versions.scan(0, move |i, v| { + #[cfg(debug_assertions)] + { + assert!( + last <= Some(v), + "`simplify` `versions` argument incorrectly sorted" + ); + last = Some(v); + } while let Some(segment) = self.segments.get(*i) { match within_bounds(v, segment) { Ordering::Less => return Some(None),