use super::node::Node;
#[allow(dead_code)]
pub fn same_leaf_path(ancestors: &[(Node, usize)], path: &[(Node, usize)]) -> bool {
if path.is_empty() {
return ancestors.is_empty();
}
let path_ancestors = &path[..path.len() - 1];
if ancestors.len() != path_ancestors.len() {
return false;
}
ancestors
.iter()
.zip(path_ancestors.iter())
.all(|((n1, i1), (n2, i2))| n1.cid() == n2.cid() && i1 == i2)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_same_leaf_path_empty_paths() {
let empty: Vec<(Node, usize)> = vec![];
assert!(same_leaf_path(&empty, &empty));
}
#[test]
fn test_same_leaf_path_empty_ancestors_non_empty_path() {
let empty: Vec<(Node, usize)> = vec![];
let node = Node::builder().leaf(true).build();
let path = vec![(node, 0)];
assert!(same_leaf_path(&empty, &path));
}
#[test]
fn test_same_leaf_path_non_empty_ancestors_empty_path() {
let node = Node::builder().leaf(false).build();
let ancestors = vec![(node, 0)];
let empty: Vec<(Node, usize)> = vec![];
assert!(!same_leaf_path(&ancestors, &empty));
}
}