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`
This commit is contained in:
commit
b54838f960
2 changed files with 15 additions and 16 deletions
|
@ -57,24 +57,23 @@ impl<K, V> BTreeMap<K, V> {
|
||||||
assert!(root_node.ascend().is_err());
|
assert!(root_node.ascend().is_err());
|
||||||
root_node.assert_back_pointers();
|
root_node.assert_back_pointers();
|
||||||
|
|
||||||
// Check consistenty of `length` and some of the navigation.
|
// Check consistency of `length` with what navigation code encounters.
|
||||||
assert_eq!(self.length, root_node.calc_length());
|
assert_eq!(self.length, root_node.calc_length());
|
||||||
assert_eq!(self.length, self.keys().count());
|
|
||||||
|
|
||||||
// Lastly, check the invariant causing the least harm.
|
// Lastly, check the invariant causing the least harm.
|
||||||
root_node.assert_min_len(if root_node.height() > 0 { 1 } else { 0 });
|
root_node.assert_min_len(if root_node.height() > 0 { 1 } else { 0 });
|
||||||
} else {
|
} else {
|
||||||
// Check consistenty of `length` and some of the navigation.
|
|
||||||
assert_eq!(self.length, 0);
|
assert_eq!(self.length, 0);
|
||||||
assert_eq!(self.length, self.keys().count());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that `assert_strictly_ascending` will encounter all keys.
|
||||||
|
assert_eq!(self.length, self.keys().count());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panics if the map is corrupted or if the keys are not in strictly
|
// Panics if the map is corrupted or if the keys are not in strictly
|
||||||
// ascending order, in the current opinion of the `Ord` implementation.
|
// ascending order, in the current opinion of the `Ord` implementation.
|
||||||
// If the `Ord` implementation does not honor transitivity, this method
|
// If the `Ord` implementation violates transitivity, this method does not
|
||||||
// does not guarantee that all the keys are unique, just that adjacent
|
// guarantee that all keys are unique, just that adjacent keys are unique.
|
||||||
// keys are unique.
|
|
||||||
fn check(&self)
|
fn check(&self)
|
||||||
where
|
where
|
||||||
K: Debug + Ord,
|
K: Debug + Ord,
|
||||||
|
@ -880,6 +879,7 @@ mod test_drain_filter {
|
||||||
map.check();
|
map.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicitly consumes the iterator, where most test cases drop it instantly.
|
||||||
#[test]
|
#[test]
|
||||||
fn consumed_keeping_all() {
|
fn consumed_keeping_all() {
|
||||||
let pairs = (0..3).map(|i| (i, i));
|
let pairs = (0..3).map(|i| (i, i));
|
||||||
|
@ -888,6 +888,7 @@ mod test_drain_filter {
|
||||||
map.check();
|
map.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicitly consumes the iterator, where most test cases drop it instantly.
|
||||||
#[test]
|
#[test]
|
||||||
fn consumed_removing_all() {
|
fn consumed_removing_all() {
|
||||||
let pairs = (0..3).map(|i| (i, i));
|
let pairs = (0..3).map(|i| (i, i));
|
||||||
|
@ -897,15 +898,7 @@ mod test_drain_filter {
|
||||||
map.check();
|
map.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
// Explicitly consumes the iterator and modifies values through it.
|
||||||
fn dropped_removing_all() {
|
|
||||||
let pairs = (0..3).map(|i| (i, i));
|
|
||||||
let mut map: BTreeMap<_, _> = pairs.collect();
|
|
||||||
map.drain_filter(|_, _| true);
|
|
||||||
assert!(map.is_empty());
|
|
||||||
map.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mutating_and_keeping() {
|
fn mutating_and_keeping() {
|
||||||
let pairs = (0..3).map(|i| (i, i));
|
let pairs = (0..3).map(|i| (i, i));
|
||||||
|
@ -922,6 +915,7 @@ mod test_drain_filter {
|
||||||
map.check();
|
map.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicitly consumes the iterator and modifies values through it.
|
||||||
#[test]
|
#[test]
|
||||||
fn mutating_and_removing() {
|
fn mutating_and_removing() {
|
||||||
let pairs = (0..3).map(|i| (i, i));
|
let pairs = (0..3).map(|i| (i, i));
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::cell::Cell;
|
||||||
use std::cmp::Ordering::{self, *};
|
use std::cmp::Ordering::{self, *};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
// Minimal type with an `Ord` implementation violating transitivity.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Cyclic3 {
|
pub enum Cyclic3 {
|
||||||
A,
|
A,
|
||||||
|
@ -34,6 +35,7 @@ impl PartialEq for Cyclic3 {
|
||||||
|
|
||||||
impl Eq for Cyclic3 {}
|
impl Eq for Cyclic3 {}
|
||||||
|
|
||||||
|
// Controls the ordering of values wrapped by `Governed`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Governor {
|
pub struct Governor {
|
||||||
flipped: Cell<bool>,
|
flipped: Cell<bool>,
|
||||||
|
@ -49,6 +51,9 @@ impl Governor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type with an `Ord` implementation that forms a total order at any moment
|
||||||
|
// (assuming that `T` respects total order), but can suddenly be made to invert
|
||||||
|
// that total order.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Governed<'a, T>(pub T, pub &'a Governor);
|
pub struct Governed<'a, T>(pub T, pub &'a Governor);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue