Skip to content

Commit d9e51bd

Browse files
committed
Add shardtree::testing::arb_prunable_tree
1 parent ebec4b7 commit d9e51bd

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

shardtree/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,7 @@ pub mod testing {
32743274
use proptest::prelude::*;
32753275
use proptest::sample::select;
32763276

3277-
pub fn arb_retention_flags() -> impl Strategy<Value = RetentionFlags> {
3277+
pub fn arb_retention_flags() -> impl Strategy<Value = RetentionFlags> + Clone {
32783278
select(vec![
32793279
RetentionFlags::EPHEMERAL,
32803280
RetentionFlags::CHECKPOINT,
@@ -3291,7 +3291,7 @@ pub mod testing {
32913291
) -> impl Strategy<Value = Tree<A::Value, V::Value>>
32923292
where
32933293
A::Value: Clone + 'static,
3294-
V::Value: Hashable + Clone + 'static,
3294+
V::Value: Clone + 'static,
32953295
{
32963296
let leaf = prop_oneof![
32973297
Just(Tree(Node::Nil)),
@@ -3313,9 +3313,25 @@ pub mod testing {
33133313
})
33143314
}
33153315

3316+
pub fn arb_prunable_tree<H: Strategy + Clone + 'static>(
3317+
arb_leaf: H,
3318+
depth: u32,
3319+
size: u32,
3320+
) -> impl Strategy<Value = PrunableTree<H::Value>>
3321+
where
3322+
H::Value: Clone + 'static,
3323+
{
3324+
arb_tree(
3325+
proptest::option::of(arb_leaf.clone().prop_map(Rc::new)),
3326+
(arb_leaf, arb_retention_flags()),
3327+
depth,
3328+
size,
3329+
)
3330+
}
3331+
33163332
/// Constructs a random shardtree of size up to 2^6 with shards of size 2^3. Returns the tree,
33173333
/// along with vectors of the checkpoint and mark positions.
3318-
pub fn arb_shardtree<H: Strategy>(
3334+
pub fn arb_shardtree<H: Strategy + Clone>(
33193335
arb_leaf: H,
33203336
) -> impl Strategy<
33213337
Value = (
@@ -3366,7 +3382,7 @@ pub mod testing {
33663382
})
33673383
}
33683384

3369-
pub fn arb_char_str() -> impl Strategy<Value = String> {
3385+
pub fn arb_char_str() -> impl Strategy<Value = String> + Clone {
33703386
let chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
33713387
(0usize..chars.len()).prop_map(move |i| chars.get(i..=i).unwrap().to_string())
33723388
}

0 commit comments

Comments
 (0)