From 676a888ae02a900540ea43b991202e0d86311a1f Mon Sep 17 00:00:00 2001 From: Witter Date: Tue, 3 Oct 2023 11:52:12 +0800 Subject: [PATCH] chore: more test & optimize test --- src/btreemap.rs | 18 ++++++++++++++++++ src/btreemap/proptests.rs | 6 ------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/btreemap.rs b/src/btreemap.rs index 07a39aa7..d424d88c 100644 --- a/src/btreemap.rs +++ b/src/btreemap.rs @@ -1412,9 +1412,11 @@ mod test { assert_eq!(btree.allocator.num_allocated_chunks(), 0); assert_eq!(btree.insert(b(&[]), b(&[])), None); + assert!(!btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 1); assert_eq!(btree.pop_last(), Some((b(&[]), b(&[])))); + assert!(btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 0); }); } @@ -1425,9 +1427,11 @@ mod test { assert_eq!(btree.allocator.num_allocated_chunks(), 0); assert_eq!(btree.insert(b(&[]), b(&[])), None); + assert!(!btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 1); assert_eq!(btree.pop_first(), Some((b(&[]), b(&[])))); + assert!(btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 0); }); } @@ -1572,6 +1576,16 @@ mod test { }); } + #[test] + fn pop_on_empty_tree_simple() { + btree_test( + |mut btree: BTreeMap, Blob<10>, Rc>>>| { + assert_eq!(btree.pop_last(), None); + assert_eq!(btree.pop_first(), None); + }, + ); + } + #[test] fn remove_case_2a_and_2c() { btree_test(|mut btree| { @@ -2053,6 +2067,8 @@ mod test { } // We've deallocated everything. + assert!(std_btree.is_empty()); + assert!(btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 0); } @@ -2093,6 +2109,8 @@ mod test { } // We've deallocated everything. + assert!(std_btree.is_empty()); + assert!(btree.is_empty()); assert_eq!(btree.allocator.num_allocated_chunks(), 0); } diff --git a/src/btreemap/proptests.rs b/src/btreemap/proptests.rs index 30c14dec..179b6619 100644 --- a/src/btreemap/proptests.rs +++ b/src/btreemap/proptests.rs @@ -202,9 +202,6 @@ fn execute_operation( } Operation::PopLast => { assert_eq!(std_btree.len(), btree.len() as usize); - if std_btree.is_empty() { - return; - } let idx = std_btree.len(); @@ -216,9 +213,6 @@ fn execute_operation( } Operation::PopFirst => { assert_eq!(std_btree.len(), btree.len() as usize); - if std_btree.is_empty() { - return; - } let idx = std_btree.len();