Skip to content

Commit

Permalink
Add IterRev to the proptests
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Nov 11, 2024
1 parent 11b5e51 commit acbe989
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/btreemap/proptests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use test_strategy::proptest;
enum Operation {
Insert { key: Vec<u8>, value: Vec<u8> },
Iter { from: usize, len: usize },
IterRev { from: usize, len: usize },
Get(usize),
Remove(usize),
Range { from: usize, len: usize },
Expand All @@ -32,6 +33,8 @@ fn operation_strategy() -> impl Strategy<Value = Operation> {
.prop_map(|(key, value)| Operation::Insert { key, value }),
5 => (any::<usize>(), any::<usize>())
.prop_map(|(from, len)| Operation::Iter { from, len }),
5 => (any::<usize>(), any::<usize>())
.prop_map(|(from, len)| Operation::IterRev { from, len }),
50 => (any::<usize>()).prop_map(Operation::Get),
15 => (any::<usize>()).prop_map(Operation::Remove),
5 => (any::<usize>(), any::<usize>())
Expand Down Expand Up @@ -210,6 +213,23 @@ fn execute_operation<M: Memory>(
assert_eq!(v1, &v2);
}
}
Operation::IterRev { from, len } => {
assert_eq!(std_btree.len(), btree.len() as usize);
if std_btree.is_empty() {
return;
}

let from = from % std_btree.len();
let len = len % std_btree.len();

eprintln!("Iterate({}, {})", from, len);
let std_iter = std_btree.iter().rev().skip(from).take(len);
let stable_iter = btree.iter().rev().skip(from).take(len);
for ((k1, v1), (k2, v2)) in std_iter.zip(stable_iter) {
assert_eq!(k1, &k2);
assert_eq!(v1, &v2);
}
}
Operation::Get(idx) => {
assert_eq!(std_btree.len(), btree.len() as usize);
if std_btree.is_empty() {
Expand Down

0 comments on commit acbe989

Please sign in to comment.