BTreeMap: extra testing unveiling mistakes in future PR
This commit is contained in:
parent
81e02708f1
commit
37ec045850
|
@ -88,6 +88,11 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
|
||||||
let min_len = if is_root { 1 } else { node::MIN_LEN };
|
let min_len = if is_root { 1 } else { node::MIN_LEN };
|
||||||
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
|
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
|
||||||
|
|
||||||
|
for idx in 0..=node.len() {
|
||||||
|
let edge = unsafe { node::Handle::new_edge(node, idx) };
|
||||||
|
assert!(edge.descend().ascend().ok().unwrap() == edge);
|
||||||
|
}
|
||||||
|
|
||||||
internal_length += node.len();
|
internal_length += node.len();
|
||||||
}
|
}
|
||||||
Position::InternalKV(kv) => {
|
Position::InternalKV(kv) => {
|
||||||
|
@ -1846,3 +1851,17 @@ fn test_into_values() {
|
||||||
assert!(values.contains(&'b'));
|
assert!(values.contains(&'b'));
|
||||||
assert!(values.contains(&'c'));
|
assert!(values.contains(&'c'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_insert_remove_intertwined() {
|
||||||
|
let loops = if cfg!(miri) { 100 } else { 1_000_000 };
|
||||||
|
let mut map = BTreeMap::new();
|
||||||
|
let mut i = 1;
|
||||||
|
for _ in 0..loops {
|
||||||
|
i = (i + 421) & 0xFF;
|
||||||
|
map.insert(i, i);
|
||||||
|
map.remove(&(0xFF - i));
|
||||||
|
}
|
||||||
|
|
||||||
|
map.check();
|
||||||
|
}
|
||||||
|
|
|
@ -613,8 +613,8 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||||
/// Adds a key/value pair and an edge to go to the right of that pair to
|
/// Adds a key/value pair, and an edge to go to the right of that pair,
|
||||||
/// the end of the node.
|
/// to the end of the node.
|
||||||
pub fn push(&mut self, key: K, val: V, edge: Root<K, V>) {
|
pub fn push(&mut self, key: K, val: V, edge: Root<K, V>) {
|
||||||
assert!(edge.height == self.height - 1);
|
assert!(edge.height == self.height - 1);
|
||||||
|
|
||||||
|
@ -630,8 +630,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a key/value pair and an edge to go to the left of that pair to
|
/// Adds a key/value pair, and an edge to go to the left of that pair,
|
||||||
/// the beginning of the node.
|
/// to the beginning of the node.
|
||||||
pub fn push_front(&mut self, key: K, val: V, edge: Root<K, V>) {
|
pub fn push_front(&mut self, key: K, val: V, edge: Root<K, V>) {
|
||||||
assert!(edge.height == self.height - 1);
|
assert!(edge.height == self.height - 1);
|
||||||
assert!(self.len() < CAPACITY);
|
assert!(self.len() < CAPACITY);
|
||||||
|
@ -1152,7 +1152,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
|
||||||
///
|
///
|
||||||
/// - The node is truncated to only contain the key/value pairs to the right of
|
/// - The node is truncated to only contain the key/value pairs to the right of
|
||||||
/// this handle.
|
/// this handle.
|
||||||
/// - The key and value pointed to by this handle and extracted.
|
/// - The key and value pointed to by this handle are extracted.
|
||||||
/// - All the key/value pairs to the right of this handle are put into a newly
|
/// - All the key/value pairs to the right of this handle are put into a newly
|
||||||
/// allocated node.
|
/// allocated node.
|
||||||
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, K, V, Root<K, V>) {
|
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, K, V, Root<K, V>) {
|
||||||
|
@ -1196,7 +1196,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
|
||||||
///
|
///
|
||||||
/// - The node is truncated to only contain the edges and key/value pairs to the
|
/// - The node is truncated to only contain the edges and key/value pairs to the
|
||||||
/// right of this handle.
|
/// right of this handle.
|
||||||
/// - The key and value pointed to by this handle and extracted.
|
/// - The key and value pointed to by this handle are extracted.
|
||||||
/// - All the edges and key/value pairs to the right of this handle are put into
|
/// - All the edges and key/value pairs to the right of this handle are put into
|
||||||
/// a newly allocated node.
|
/// a newly allocated node.
|
||||||
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Internal>, K, V, Root<K, V>) {
|
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Internal>, K, V, Root<K, V>) {
|
||||||
|
|
Loading…
Reference in New Issue