Skip to content

Commit 3b6c52d

Browse files
committed
Added test to check min, max and minmax behaviour when several elements are equally minimum or maximum
1 parent 09d8a8c commit 3b6c52d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/quick.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,4 +1346,29 @@ quickcheck! {
13461346
);
13471347
}
13481348
}
1349+
1350+
// This should check that if multiple elements are equally minimum or maximum
1351+
// then `max`, `min` and `minmax` pick the first minimum and the last maximum.
1352+
// This is to be consistent with `std::iter::max` and `std::iter::min`.
1353+
fn correct_grouping_map_by_min_max_minmax_order_modulo_key() -> () {
1354+
use itertools::MinMaxResult;
1355+
1356+
let lookup = (0..=10)
1357+
.into_grouping_map_by(|_| 0)
1358+
.max_by(|_, _, _| Ordering::Equal);
1359+
1360+
assert_eq!(lookup[&0], 10);
1361+
1362+
let lookup = (0..=10)
1363+
.into_grouping_map_by(|_| 0)
1364+
.min_by(|_, _, _| Ordering::Equal);
1365+
1366+
assert_eq!(lookup[&0], 0);
1367+
1368+
let lookup = (0..=10)
1369+
.into_grouping_map_by(|_| 0)
1370+
.minmax_by(|_, _, _| Ordering::Equal);
1371+
1372+
assert_eq!(lookup[&0], MinMaxResult::MinMax(0, 10));
1373+
}
13491374
}

0 commit comments

Comments
 (0)