Skip to content

Commit b54838f

Browse files
authored
Rollup merge of #79295 - ssomers:btree_fix_78903, r=Mark-Simulacrum
BTreeMap: fix minor testing mistakes in #78903 Mostly a duplicate test case r? `@Mark-Simulacrum`
2 parents 138845d + 9186c07 commit b54838f

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

library/alloc/src/collections/btree/map/tests.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,23 @@ impl<K, V> BTreeMap<K, V> {
5757
assert!(root_node.ascend().is_err());
5858
root_node.assert_back_pointers();
5959

60-
// Check consistenty of `length` and some of the navigation.
60+
// Check consistency of `length` with what navigation code encounters.
6161
assert_eq!(self.length, root_node.calc_length());
62-
assert_eq!(self.length, self.keys().count());
6362

6463
// Lastly, check the invariant causing the least harm.
6564
root_node.assert_min_len(if root_node.height() > 0 { 1 } else { 0 });
6665
} else {
67-
// Check consistenty of `length` and some of the navigation.
6866
assert_eq!(self.length, 0);
69-
assert_eq!(self.length, self.keys().count());
7067
}
68+
69+
// Check that `assert_strictly_ascending` will encounter all keys.
70+
assert_eq!(self.length, self.keys().count());
7171
}
7272

7373
// Panics if the map is corrupted or if the keys are not in strictly
7474
// ascending order, in the current opinion of the `Ord` implementation.
75-
// If the `Ord` implementation does not honor transitivity, this method
76-
// does not guarantee that all the keys are unique, just that adjacent
77-
// keys are unique.
75+
// If the `Ord` implementation violates transitivity, this method does not
76+
// guarantee that all keys are unique, just that adjacent keys are unique.
7877
fn check(&self)
7978
where
8079
K: Debug + Ord,
@@ -880,6 +879,7 @@ mod test_drain_filter {
880879
map.check();
881880
}
882881

882+
// Explicitly consumes the iterator, where most test cases drop it instantly.
883883
#[test]
884884
fn consumed_keeping_all() {
885885
let pairs = (0..3).map(|i| (i, i));
@@ -888,6 +888,7 @@ mod test_drain_filter {
888888
map.check();
889889
}
890890

891+
// Explicitly consumes the iterator, where most test cases drop it instantly.
891892
#[test]
892893
fn consumed_removing_all() {
893894
let pairs = (0..3).map(|i| (i, i));
@@ -897,15 +898,7 @@ mod test_drain_filter {
897898
map.check();
898899
}
899900

900-
#[test]
901-
fn dropped_removing_all() {
902-
let pairs = (0..3).map(|i| (i, i));
903-
let mut map: BTreeMap<_, _> = pairs.collect();
904-
map.drain_filter(|_, _| true);
905-
assert!(map.is_empty());
906-
map.check();
907-
}
908-
901+
// Explicitly consumes the iterator and modifies values through it.
909902
#[test]
910903
fn mutating_and_keeping() {
911904
let pairs = (0..3).map(|i| (i, i));
@@ -922,6 +915,7 @@ mod test_drain_filter {
922915
map.check();
923916
}
924917

918+
// Explicitly consumes the iterator and modifies values through it.
925919
#[test]
926920
fn mutating_and_removing() {
927921
let pairs = (0..3).map(|i| (i, i));

library/alloc/src/collections/btree/map/tests/ord_chaos.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cell::Cell;
22
use std::cmp::Ordering::{self, *};
33
use std::ptr;
44

5+
// Minimal type with an `Ord` implementation violating transitivity.
56
#[derive(Debug)]
67
pub enum Cyclic3 {
78
A,
@@ -34,6 +35,7 @@ impl PartialEq for Cyclic3 {
3435

3536
impl Eq for Cyclic3 {}
3637

38+
// Controls the ordering of values wrapped by `Governed`.
3739
#[derive(Debug)]
3840
pub struct Governor {
3941
flipped: Cell<bool>,
@@ -49,6 +51,9 @@ impl Governor {
4951
}
5052
}
5153

54+
// Type with an `Ord` implementation that forms a total order at any moment
55+
// (assuming that `T` respects total order), but can suddenly be made to invert
56+
// that total order.
5257
#[derive(Debug)]
5358
pub struct Governed<'a, T>(pub T, pub &'a Governor);
5459

0 commit comments

Comments
 (0)