cleanup path fn and add test coverage (#1201)

This commit is contained in:
Antioch Peverell
2018-06-26 09:42:12 -04:00
committed by GitHub
parent 8ff8c8a128
commit 14667bfad6
2 changed files with 11 additions and 6 deletions
+3 -6
View File
@@ -712,14 +712,11 @@ pub fn is_left_sibling(pos: u64) -> bool {
/// The size (and therefore the set of peaks) of the MMR
/// is defined by last_pos.
pub fn path(pos: u64, last_pos: u64) -> Vec<u64> {
let mut path = vec![pos];
let mut path = vec![];
let mut current = pos;
while current + 1 <= last_pos {
while current <= last_pos {
path.push(current);
let (parent, _) = family(current);
if parent > last_pos {
break;
}
path.push(parent);
current = parent;
}
path
+8
View File
@@ -97,6 +97,14 @@ fn various_families() {
assert_eq!(pmmr::family(1_000), (1_001, 997));
}
#[test]
fn test_paths() {
assert_eq!(pmmr::path(1, 1), [1]);
assert_eq!(pmmr::path(1, 3), [1, 3]);
assert_eq!(pmmr::path(2, 3), [2, 3]);
assert_eq!(pmmr::path(4, 16), [4, 6, 7, 15]);
}
#[test]
fn test_is_left_sibling() {
assert_eq!(pmmr::is_left_sibling(1), true);