Skip to content

Commit

Permalink
chore: more test & optimize test
Browse files Browse the repository at this point in the history
  • Loading branch information
witter-deland committed Oct 3, 2023
1 parent 5466117 commit 676a888
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand All @@ -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);
});
}
Expand Down Expand Up @@ -1572,6 +1576,16 @@ mod test {
});
}

#[test]
fn pop_on_empty_tree_simple() {
btree_test(
|mut btree: BTreeMap<Blob<10>, Blob<10>, Rc<RefCell<Vec<u8>>>>| {
assert_eq!(btree.pop_last(), None);
assert_eq!(btree.pop_first(), None);
},
);
}

#[test]
fn remove_case_2a_and_2c() {
btree_test(|mut btree| {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 0 additions & 6 deletions src/btreemap/proptests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ fn execute_operation<M: Memory>(
}
Operation::PopLast => {
assert_eq!(std_btree.len(), btree.len() as usize);
if std_btree.is_empty() {
return;
}

let idx = std_btree.len();

Expand All @@ -216,9 +213,6 @@ fn execute_operation<M: Memory>(
}
Operation::PopFirst => {
assert_eq!(std_btree.len(), btree.len() as usize);
if std_btree.is_empty() {
return;
}

let idx = std_btree.len();

Expand Down

0 comments on commit 676a888

Please sign in to comment.