Skip to content

Commit 32a966c

Browse files
committed
add leaf_into tests
1 parent 0cfb79d commit 32a966c

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

tests/leaf_nodes.rs

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,69 @@
22

33
use orx_tree::*;
44

5+
/// https://github.com/orxfun/orx-tree/issues/183
56
#[test]
6-
fn root_into_new_tree() {
7+
fn leaf_into_new_tree() {
78
let mut tree = DynTree::new(0);
9+
let idx = tree.root_mut().push_child(1);
810

9-
let tree2: DynTree<_> = tree.root_mut().into_new_tree();
11+
let tree2: DynTree<_> = tree.node_mut(idx).into_new_tree();
1012

1113
assert_eq!(tree2.len(), 1);
1214
assert_eq!(
1315
tree2.root().walk::<Dfs>().copied().collect::<Vec<_>>(),
14-
vec![0]
16+
vec![1]
1517
);
1618
}
1719

18-
/// https://github.com/orxfun/orx-tree/issues/183
1920
#[test]
20-
fn leaf_into_new_tree() {
21+
fn root_into_new_tree() {
2122
let mut tree = DynTree::new(0);
22-
tree.root_mut().push_child(1);
2323

24-
let tree2: DynTree<_> = tree
25-
.root_mut()
26-
.children_mut()
27-
.nth(0)
28-
.unwrap()
29-
.into_new_tree();
24+
let tree2: DynTree<_> = tree.root_mut().into_new_tree();
3025

3126
assert_eq!(tree2.len(), 1);
3227
assert_eq!(
3328
tree2.root().walk::<Dfs>().copied().collect::<Vec<_>>(),
34-
vec![1]
29+
vec![0]
3530
);
3631
}
32+
33+
#[test]
34+
fn leaf_into_walk() {
35+
let mut tree = DynTree::new(0);
36+
let idx = tree.root_mut().push_child(1);
37+
38+
let values: Vec<_> = tree.node_mut(idx).into_walk::<Dfs>().collect();
39+
assert_eq!(values, vec![1]);
40+
41+
let remaining: Vec<_> = tree.root().walk::<Dfs>().copied().collect();
42+
assert_eq!(remaining, vec![0]);
43+
}
44+
45+
#[test]
46+
fn leaf_into_leaves() {
47+
let mut tree = DynTree::new(0);
48+
let idx = tree.root_mut().push_child(1);
49+
50+
let values: Vec<_> = tree.node_mut(idx).into_leaves::<Dfs>().collect();
51+
assert_eq!(values, vec![1]);
52+
53+
let remaining: Vec<_> = tree.root().walk::<Dfs>().copied().collect();
54+
assert_eq!(remaining, vec![0]);
55+
}
56+
57+
#[test]
58+
fn leaf_into_subtree() {
59+
let mut tree = DynTree::new(0);
60+
let idx = tree.root_mut().push_child(1);
61+
62+
let subtree = tree.node_mut(idx).into_subtree();
63+
let mut tree2 = DynTree::new(42);
64+
tree2.root_mut().push_child_tree(subtree);
65+
let values: Vec<_> = tree2.root().walk::<Dfs>().copied().collect();
66+
assert_eq!(values, vec![42, 1]);
67+
68+
let remaining: Vec<_> = tree.root().walk::<Dfs>().copied().collect();
69+
assert_eq!(remaining, vec![0]);
70+
}

0 commit comments

Comments
 (0)