3 #include "test/helpers.h"
8 Tree
* t
= tree_new(int);
11 tree_add_child(t
, t
->root
, 1);
12 tree_add_child(t
, t
->root
, 2);
13 tree_add_child(t
, t
->root
, 3);
14 tree_add_child(t
, t
->root
->firstChild
, 1);
15 tree_add_child(t
, t
->root
->firstChild
, 2);
16 tree_add_child(t
, t
->root
->firstChild
->next
, 1);
17 tree_add_child(t
, t
->root
->firstChild
->next
, 2);
18 tree_add_child(t
, t
->root
->firstChild
->next
, 3);
19 tree_add_child(t
, t
->root
->firstChild
->next
, 4);
22 lu_assert(tree_empty(t
));
29 Tree
* t
= tree_new(int);
32 tree_add_child(t
, t
->root
, 1);
33 tree_add_child(t
, t
->root
, 2);
34 tree_add_child(t
, t
->root
, 3);
35 lu_assert_int_eq(tree_size(t
), 4);
37 tree_add_child(t
, t
->root
->firstChild
, 1);
38 tree_add_child(t
, t
->root
->firstChild
, 2);
39 lu_assert_int_eq(tree_size(t
), 6);
41 tree_add_child(t
, t
->root
->firstChild
->next
, 1);
42 tree_add_child(t
, t
->root
->firstChild
->next
, 2);
43 tree_add_child(t
, t
->root
->firstChild
->next
, 3);
44 tree_add_child(t
, t
->root
->firstChild
->next
, 4);
45 lu_assert_int_eq(tree_size(t
), 10);
50 void t_tree_add_remove()
52 Tree
* t
= tree_new(int);
55 tree_add_child(t
, t
->root
, 1);
56 tree_add_child(t
, t
->root
, 2);
57 tree_add_child(t
, t
->root
, 3);
58 tree_add_child(t
, t
->root
->firstChild
, 1);
59 tree_add_child(t
, t
->root
->firstChild
, 2);
60 tree_add_child(t
, t
->root
->firstChild
->next
, 1);
61 tree_add_child(t
, t
->root
->firstChild
->next
, 2);
62 tree_add_child(t
, t
->root
->firstChild
->next
, 3);
63 tree_add_child(t
, t
->root
->firstChild
->next
, 4);
64 tree_add_child(t
, t
->root
->lastChild
, 1);
65 tree_add_child(t
, t
->root
->lastChild
, 2);
66 tree_add_child(t
, t
->root
->lastChild
, 3);
67 lu_assert_int_eq(tree_size(t
), 13);
69 tree_remove(t
, t
->root
->lastChild
);
70 lu_assert_int_eq(tree_size(t
), 9);
71 tree_rm_childs(t
, t
->root
->firstChild
);
72 lu_assert_int_eq(tree_size(t
), 7);
79 Tree
* t
= tree_new(int);
82 tree_add_child(t
, t
->root
, 1);
83 tree_add_child(t
, t
->root
, 2);
84 tree_add_child(t
, t
->root
, 3);
85 tree_add_child(t
, t
->root
->firstChild
, 4);
86 tree_add_child(t
, t
->root
->firstChild
, 5);
87 tree_add_child(t
, t
->root
->firstChild
->next
, 6);
88 tree_add_child(t
, t
->root
->firstChild
->next
, 7);
89 tree_add_child(t
, t
->root
->firstChild
->next
, 8);
90 tree_add_child(t
, t
->root
->firstChild
->next
, 9);
92 TreeIterator
* ti
= tree_get_iterator(t
, IN_BREADTH
);
94 for (int i
= 0; i
< 10; i
++)
96 lu_assert(treeI_has_data(ti
));
98 lu_assert_int_eq(a
, i
);
108 Tree
* t
= tree_new(int);
111 tree_add_child(t
, t
->root
, 1);
112 tree_add_child(t
, t
->root
, 2);
113 tree_add_child(t
, t
->root
, 3);
114 tree_add_child(t
, t
->root
->firstChild
, 1);
115 tree_add_child(t
, t
->root
->firstChild
, 2);
116 tree_add_child(t
, t
->root
->firstChild
->next
, 1);
117 tree_add_child(t
, t
->root
->firstChild
->next
, 2);
118 tree_add_child(t
, t
->root
->firstChild
->next
, 3);
119 tree_add_child(t
, t
->root
->firstChild
->next
, 4);
121 Tree
* tc
= tree_copy(t
);
122 lu_assert_int_eq(t
->size
, tc
->size
);
124 TreeIterator
* ti
= tree_get_iterator(t
, IN_DEPTH
);
125 TreeIterator
* tci
= tree_get_iterator(tc
, IN_DEPTH
);
127 while (treeI_has_data(ti
))
131 lu_assert_int_eq(a
, b
);
133 treeI_move_next(tci
);