def test_is_node_on_tree(self): root = Node("root", None, None) child = root.create_child("child") grandchild = child.create_child("grandchild") tree = Tree("tree", root) self.assertTrue(tree.is_node_on_tree(root)) self.assertFalse(tree.is_node_on_tree(child)) self.assertFalse(tree.is_node_on_tree(grandchild)) pass
def test_init(self): root = Node("root", None, None) child_1 = root.create_child("child1") grandchild_1 = child_1.create_child("grandchild1") grandchild_2 = child_1.create_child("grandchild2") child_2 = root.create_child("child2") child_3 = root.create_child("child3") grandchild_3 = child_3.create_child("grandchild3") tree = Tree("tree", root) tree.add_node_to_tree(grandchild_1) tree.add_node_to_tree(grandchild_2) tree.add_node_to_tree(child_2) tree.add_node_to_tree(grandchild_3) leaf_values = {grandchild_1: np.array([1.0, 2.0, 3.0]), grandchild_2: np.array([1.0, 2.0, 3.0]), grandchild_3: np.array([1.0, 2.0, 3.0]), child_2: np.array([1.0, 2.0, 3.0])} nodes_for_store = {root, child_1, child_3} agg = Aggregator(tree, leaf_values, nodes_for_store) agg.process() pass
def __init__(self, tree: Tree, leaf_values: Dict[Node, ndarray], nodes_for_store: Set[Node]): self._tree = tree self._leaf_values = leaf_values self._nodes_for_store = nodes_for_store self._stored_values = {} self._roll_stack = tree.get_tree_depth_stack() self.__parent_children_map = tree.scan_parent_children_map() self.__leaf_nodes = tree.scan_leaf_nodes() self.__current_level = self._roll_stack.pop() self.__current_level_values = self.__source_leaf_values() self.__store_node_values(self.__current_level_values) pass
def test_gen_node_serial_number(self): root = Node("root", None, None) child_1 = root.create_child("child1") grandchild_1 = child_1.create_child("grandchild1") grandchild_2 = child_1.create_child("grandchild2") child_2 = root.create_child("child2") child_3 = root.create_child("child3") grandchild_3 = child_3.create_child("grandchild3") tree = Tree("tree", root) tree.add_node_to_tree(grandchild_1) tree.add_node_to_tree(grandchild_2) tree.add_node_to_tree(child_2) tree.add_node_to_tree(grandchild_3) tree.get_node_serial_number() pass
def test_parent_children_map(self): root = Node("root", None, None) child_1 = root.create_child("child1") grandchild_1 = child_1.create_child("grandchild1") grandchild_2 = child_1.create_child("grandchild2") child_2 = root.create_child("child2") child_3 = root.create_child("child3") grandchild_3 = child_3.create_child("grandchild3") tree = Tree("tree", root) tree.add_node_to_tree(grandchild_1) tree.add_node_to_tree(grandchild_2) tree.add_node_to_tree(child_2) tree.add_node_to_tree(grandchild_3) v = tree.scan_parent_children_map() pass
def test_drop_node_from_tree(self): root = Node("root", None, None) child = root.create_child("child") grandchild_1 = child.create_child("grandchild1") grandchild_2 = child.create_child("grandchild2") tree = Tree("tree", root) self.assertTrue(tree.is_node_on_tree(root)) self.assertFalse(tree.is_node_on_tree(child)) self.assertFalse(tree.is_node_on_tree(grandchild_1)) self.assertFalse(tree.is_node_on_tree(grandchild_2)) tree.add_node_to_tree(grandchild_1) self.assertTrue(tree.is_node_on_tree(root)) self.assertTrue(tree.is_node_on_tree(child)) self.assertTrue(tree.is_node_on_tree(grandchild_1)) self.assertFalse(tree.is_node_on_tree(grandchild_2)) tree.add_node_to_tree(grandchild_2) self.assertTrue(tree.is_node_on_tree(grandchild_2)) tree.drop_node_from_tree(grandchild_2) self.assertTrue(tree.is_node_on_tree(root)) self.assertTrue(tree.is_node_on_tree(child)) self.assertTrue(tree.is_node_on_tree(grandchild_1)) self.assertFalse(tree.is_node_on_tree(grandchild_2)) tree.drop_node_from_tree(child) self.assertTrue(tree.is_node_on_tree(root)) self.assertFalse(tree.is_node_on_tree(child)) self.assertFalse(tree.is_node_on_tree(grandchild_1)) self.assertFalse(tree.is_node_on_tree(grandchild_2)) pass