|
2 | 2 |
|
3 | 3 | use orx_tree::*; |
4 | 4 |
|
| 5 | +/// https://github.com/orxfun/orx-tree/issues/183 |
5 | 6 | #[test] |
6 | | -fn root_into_new_tree() { |
| 7 | +fn leaf_into_new_tree() { |
7 | 8 | let mut tree = DynTree::new(0); |
| 9 | + let idx = tree.root_mut().push_child(1); |
8 | 10 |
|
9 | | - let tree2: DynTree<_> = tree.root_mut().into_new_tree(); |
| 11 | + let tree2: DynTree<_> = tree.node_mut(idx).into_new_tree(); |
10 | 12 |
|
11 | 13 | assert_eq!(tree2.len(), 1); |
12 | 14 | assert_eq!( |
13 | 15 | tree2.root().walk::<Dfs>().copied().collect::<Vec<_>>(), |
14 | | - vec![0] |
| 16 | + vec![1] |
15 | 17 | ); |
16 | 18 | } |
17 | 19 |
|
18 | | -/// https://github.com/orxfun/orx-tree/issues/183 |
19 | 20 | #[test] |
20 | | -fn leaf_into_new_tree() { |
| 21 | +fn root_into_new_tree() { |
21 | 22 | let mut tree = DynTree::new(0); |
22 | | - tree.root_mut().push_child(1); |
23 | 23 |
|
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(); |
30 | 25 |
|
31 | 26 | assert_eq!(tree2.len(), 1); |
32 | 27 | assert_eq!( |
33 | 28 | tree2.root().walk::<Dfs>().copied().collect::<Vec<_>>(), |
34 | | - vec![1] |
| 29 | + vec![0] |
35 | 30 | ); |
36 | 31 | } |
| 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