Skip to content

Commit 9186c07

Browse files
committed
BTreeMap: fix minor testing mistakes in rust-lang#78903
1 parent 20328b5 commit 9186c07

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
@@ -56,24 +56,23 @@ impl<K, V> BTreeMap<K, V> {
5656
assert!(root_node.ascend().is_err());
5757
root_node.assert_back_pointers();
5858

59-
// Check consistenty of `length` and some of the navigation.
59+
// Check consistency of `length` with what navigation code encounters.
6060
assert_eq!(self.length, root_node.calc_length());
61-
assert_eq!(self.length, self.keys().count());
6261

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

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

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

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

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

917+
// Explicitly consumes the iterator and modifies values through it.
924918
#[test]
925919
fn mutating_and_removing() {
926920
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)