Commit 41cd193d authored by SirBlueRabbit's avatar SirBlueRabbit
Browse files

rotate reversed test

parent 854ca0c0
......@@ -293,6 +293,56 @@ mod tests {
assert_eq!(lct[c_label].parent, Some(p_label));
assert_eq!(lct[d_label].parent, Some(g_label));
}
#[test]
fn rotate_reversed() {
let mut lct = Pool::with_capacity(7);
// define nodes
let o_label = lct.add_node("node");
let p_label = lct.add_node("parent");
let g_label = lct.add_node("grandparent");
let a_label = lct.add_node("a");
let b_label = lct.add_node("b");
let c_label = lct.add_node("c");
let d_label = lct.add_node("d");
// link nodes
lct[o_label].children = [Some(a_label), Some(b_label)];
lct[p_label].children = [Some(o_label), Some(c_label)];
lct[g_label].children = [Some(p_label), Some(d_label)];
lct[o_label].parent = Some(p_label);
lct[p_label].parent = Some(g_label);
lct[a_label].parent = Some(o_label);
lct[b_label].parent = Some(o_label);
lct[c_label].parent = Some(p_label);
lct[d_label].parent = Some(g_label);
// reverse origin
lct[o_label].reversed = true;
// rotate
lct.rotate(o_label);
dbg!(lct.clone());
// check children
assert_eq!(lct[o_label].children, [Some(p_label), Some(b_label)]);
assert_eq!(lct[p_label].children, [Some(a_label), Some(c_label)]);
assert_eq!(lct[g_label].children, [Some(o_label), Some(d_label)]);
assert_eq!(lct[a_label].children, [None, None]);
assert_eq!(lct[b_label].children, [None, None]);
assert_eq!(lct[c_label].children, [None, None]);
assert_eq!(lct[d_label].children, [None, None]);
// check parents
assert_eq!(lct[o_label].parent, Some(g_label));
assert_eq!(lct[p_label].parent, Some(o_label));
assert_eq!(lct[g_label].parent, None);
assert_eq!(lct[a_label].parent, Some(p_label));
assert_eq!(lct[b_label].parent, Some(o_label));
assert_eq!(lct[c_label].parent, Some(p_label));
assert_eq!(lct[d_label].parent, Some(g_label));
}
}
/*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment