Add extra tests, all passing
This commit is contained in:
parent
58b69e9ba6
commit
827e1c62d9
@ -5,7 +5,7 @@ where
|
||||
T: CachedTreeHash<T> + TreeHash,
|
||||
{
|
||||
fn new_tree_hash_cache(&self, depth: usize) -> Result<TreeHashCache, Error> {
|
||||
let mut overlay = self.tree_hash_cache_overlay(0, depth)?;
|
||||
let overlay = self.tree_hash_cache_overlay(0, depth)?;
|
||||
|
||||
let mut cache = match T::tree_hash_type() {
|
||||
TreeHashType::Basic => TreeHashCache::from_bytes(
|
||||
|
@ -183,6 +183,7 @@ impl TreeHashCache {
|
||||
.iter()
|
||||
.skip(overlay_index)
|
||||
.position(|o| o.depth <= depth)
|
||||
.and_then(|i| Some(i + overlay_index))
|
||||
.unwrap_or_else(|| self.overlays.len());
|
||||
|
||||
self.overlays.splice(overlay_index..end, vec![]);
|
||||
|
@ -231,8 +231,7 @@ pub struct StructWithVecOfStructs {
|
||||
pub c: Vec<Inner>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_with_vec_of_structs() {
|
||||
fn get_struct_with_vec_of_structs() -> Vec<StructWithVecOfStructs> {
|
||||
let inner_a = Inner {
|
||||
a: 12,
|
||||
b: 13,
|
||||
@ -285,21 +284,62 @@ fn test_struct_with_vec_of_structs() {
|
||||
..a.clone()
|
||||
};
|
||||
|
||||
vec![a, b, c, d, e, f]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_with_vec_of_structs() {
|
||||
let variants = get_struct_with_vec_of_structs();
|
||||
|
||||
test_routine(variants[0].clone(), variants.clone());
|
||||
test_routine(variants[1].clone(), variants.clone());
|
||||
test_routine(variants[2].clone(), variants.clone());
|
||||
test_routine(variants[3].clone(), variants.clone());
|
||||
test_routine(variants[4].clone(), variants.clone());
|
||||
test_routine(variants[5].clone(), variants.clone());
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TreeHash, CachedTreeHash)]
|
||||
pub struct StructWithVecOfStructWithVecOfStructs {
|
||||
pub a: Vec<StructWithVecOfStructs>,
|
||||
pub b: u64,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_with_vec_of_struct_with_vec_of_structs() {
|
||||
let structs = get_struct_with_vec_of_structs();
|
||||
|
||||
let variants = vec![
|
||||
a.clone(),
|
||||
b.clone(),
|
||||
c.clone(),
|
||||
d.clone(),
|
||||
e.clone(),
|
||||
f.clone(),
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[..].to_vec(),
|
||||
b: 99,
|
||||
},
|
||||
StructWithVecOfStructWithVecOfStructs { a: vec![], b: 99 },
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[0..2].to_vec(),
|
||||
b: 99,
|
||||
},
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[0..2].to_vec(),
|
||||
b: 100,
|
||||
},
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[0..1].to_vec(),
|
||||
b: 100,
|
||||
},
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[0..4].to_vec(),
|
||||
b: 100,
|
||||
},
|
||||
StructWithVecOfStructWithVecOfStructs {
|
||||
a: structs[0..5].to_vec(),
|
||||
b: 8,
|
||||
},
|
||||
];
|
||||
|
||||
test_routine(a, variants.clone());
|
||||
test_routine(b, variants.clone());
|
||||
test_routine(c, variants.clone());
|
||||
test_routine(d, variants.clone());
|
||||
test_routine(e, variants.clone());
|
||||
test_routine(f, variants);
|
||||
for v in &variants {
|
||||
test_routine(v.clone(), variants.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, TreeHash, CachedTreeHash)]
|
||||
|
Loading…
Reference in New Issue
Block a user