modes:pair:tests: refactor ordering test.

This commit is contained in:
2026-04-04 04:17:21 +01:00
committed by oreodave
parent 8bacbfbde3
commit df79488cec

View File

@@ -206,23 +206,12 @@ mod tests {
#[test] #[test]
fn ordering() { fn ordering() {
fn expected_ordering_relation(p1: &Pair, p2: &Pair) -> bool { fn expected_ordering_relation(p1: &Pair, p2: &Pair) -> bool {
match (p1.cmp(p2), p1.1.cmp(&p2.1)) { match (p1.cmp(p2), p1.1.cmp(&p2.1), p1.0.cmp(&p2.0)) {
// For any two pairs, we expect the high cards to dictate the // For any two pairs, we expect the high cards to dictate the
// ordering of the pairs - the lower card should be irrelevant. // ordering of the pairs first. The low card only matters if
(x, y) if x == y => true, // the high cards are equivalent.
(x, Ordering::Equal, z) if x == z => true,
// The only instances where the high card may not dictate card (x, y, _) if x == y => true,
// ordering is if both pairs have equivalent high cards and
// exclusively one of the pairs is improper - pairs that are
// improper should be sorted less than the proper one.
(Ordering::Less, Ordering::Equal) => {
// p1 is improper, p2 is proper => p1 < p2
p1.is_improper() && p2.is_proper()
}
(Ordering::Greater, Ordering::Equal) => {
// p2 is improper, p1 is proper => p1 > p2
p2.is_improper() && p1.is_proper()
}
_ => false, _ => false,
} }
} }