about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStein Somers <git@steinsomers.be>2020-11-22 13:06:12 +0100
committerStein Somers <git@steinsomers.be>2020-11-22 13:37:39 +0100
commit9186c073fc411ec55ce9bfa12bbaaf76fc598037 (patch)
tree820e7f54d8d581e496f8c5e594260e32f731b93c
parent20328b532336017213ccb4095740955d81060ebc (diff)
downloadrust-9186c073fc411ec55ce9bfa12bbaaf76fc598037.tar.gz
rust-9186c073fc411ec55ce9bfa12bbaaf76fc598037.zip
BTreeMap: fix minor testing mistakes in #78903
-rw-r--r--library/alloc/src/collections/btree/map/tests.rs26
-rw-r--r--library/alloc/src/collections/btree/map/tests/ord_chaos.rs5
2 files changed, 15 insertions, 16 deletions
diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs
index f15959a1665..74e61e56e21 100644
--- a/library/alloc/src/collections/btree/map/tests.rs
+++ b/library/alloc/src/collections/btree/map/tests.rs
@@ -56,24 +56,23 @@ impl<K, V> BTreeMap<K, V> {
             assert!(root_node.ascend().is_err());
             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, self.keys().count());
 
             // Lastly, check the invariant causing the least harm.
             root_node.assert_min_len(if root_node.height() > 0 { 1 } else { 0 });
         } else {
-            // Check consistenty of `length` and some of the navigation.
             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
     // ascending order, in the current opinion of the `Ord` implementation.
-    // If the `Ord` implementation does not honor transitivity, this method
-    // does not guarantee that all the keys are unique, just that adjacent
-    // keys are unique.
+    // If the `Ord` implementation violates transitivity, this method does not
+    // guarantee that all keys are unique, just that adjacent keys are unique.
     fn check(&self)
     where
         K: Debug + Ord,
@@ -879,6 +878,7 @@ mod test_drain_filter {
         map.check();
     }
 
+    // Explicitly consumes the iterator, where most test cases drop it instantly.
     #[test]
     fn consumed_keeping_all() {
         let pairs = (0..3).map(|i| (i, i));
@@ -887,6 +887,7 @@ mod test_drain_filter {
         map.check();
     }
 
+    // Explicitly consumes the iterator, where most test cases drop it instantly.
     #[test]
     fn consumed_removing_all() {
         let pairs = (0..3).map(|i| (i, i));
@@ -896,15 +897,7 @@ mod test_drain_filter {
         map.check();
     }
 
-    #[test]
-    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();
-    }
-
+    // Explicitly consumes the iterator and modifies values through it.
     #[test]
     fn mutating_and_keeping() {
         let pairs = (0..3).map(|i| (i, i));
@@ -921,6 +914,7 @@ mod test_drain_filter {
         map.check();
     }
 
+    // Explicitly consumes the iterator and modifies values through it.
     #[test]
     fn mutating_and_removing() {
         let pairs = (0..3).map(|i| (i, i));
diff --git a/library/alloc/src/collections/btree/map/tests/ord_chaos.rs b/library/alloc/src/collections/btree/map/tests/ord_chaos.rs
index 91d1d6ea9ef..96ce7c15790 100644
--- a/library/alloc/src/collections/btree/map/tests/ord_chaos.rs
+++ b/library/alloc/src/collections/btree/map/tests/ord_chaos.rs
@@ -2,6 +2,7 @@ use std::cell::Cell;
 use std::cmp::Ordering::{self, *};
 use std::ptr;
 
+// Minimal type with an `Ord` implementation violating transitivity.
 #[derive(Debug)]
 pub enum Cyclic3 {
     A,
@@ -34,6 +35,7 @@ impl PartialEq for Cyclic3 {
 
 impl Eq for Cyclic3 {}
 
+// Controls the ordering of values wrapped by `Governed`.
 #[derive(Debug)]
 pub struct Governor {
     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)]
 pub struct Governed<'a, T>(pub T, pub &'a Governor);