Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
 def test_node_level(self):
     root = Node('root')
     child = root.create_child('child')
     grand_child = child.create_child('grandchild')
     self.assertEqual(1, root.count_node_level())
     self.assertEqual(2, child.count_node_level())
     self.assertEqual(3, grand_child.count_node_level())
     pass
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
 def test_get_name_full(self):
     name_root = 'root'
     name_child = 'child'
     root = Node(name_root)
     child = root.create_child(name_child)
     self.assertEqual(name_root, root.get_name())
     self.assertEqual(name_root, root.get_name_full())
     self.assertEqual(name_child, child.get_name())
     self.assertEqual(name_root + Node.JOINER_NAME + name_child, child.get_name_full())
     pass
Пример #8
0
    def test_is_my_parent(self):
        root = Node('root')
        child1 = root.create_child('child1')
        child2 = root.create_child('child2')
        grandchild = child1.create_child('grandchild')

        root_other = Node('other_root')
        child_other = root_other.create_child('child_1')

        self.assertFalse(root.is_my_parent(root))
        self.assertFalse(root.is_my_parent(child1))
        self.assertFalse(root.is_my_parent(child2))
        self.assertFalse(root.is_my_parent(grandchild))
        self.assertFalse(root.is_my_parent(root_other))
        self.assertFalse(root.is_my_parent(child_other))

        self.assertTrue(child1.is_my_parent(root))
        self.assertFalse(child1.is_my_parent(child1))
        self.assertFalse(child1.is_my_parent(child2))
        self.assertFalse(child1.is_my_parent(grandchild))
        self.assertFalse(child1.is_my_parent(root_other))
        self.assertFalse(child1.is_my_parent(child_other))

        self.assertTrue(child2.is_my_parent(root))
        self.assertFalse(child2.is_my_parent(child1))
        self.assertFalse(child2.is_my_parent(child2))
        self.assertFalse(child2.is_my_parent(grandchild))
        self.assertFalse(child2.is_my_parent(root_other))
        self.assertFalse(child2.is_my_parent(child_other))

        self.assertFalse(grandchild.is_my_parent(root))
        self.assertTrue(grandchild.is_my_parent(child1))
        self.assertFalse(grandchild.is_my_parent(child2))
        self.assertFalse(grandchild.is_my_parent(grandchild))
        self.assertFalse(grandchild.is_my_parent(root_other))
        self.assertFalse(grandchild.is_my_parent(child_other))

        pass
Пример #9
0
    def test_add_node(self):
        root = Node('root', None, None)
        child_linked = root.create_child('child_linked')
        child_unlinked = Node('child', root, None)

        self.assertTrue(root.is_my_child(child_linked))
        self.assertTrue(child_linked.is_my_parent(root))
        self.assertFalse(root.is_my_child(child_unlinked))
        self.assertTrue(child_unlinked.is_my_parent(root))

        root.add_child(child_unlinked)
        self.assertTrue(root.is_my_child(child_linked))
        self.assertTrue(child_linked.is_my_parent(root))
        self.assertTrue(root.is_my_child(child_unlinked))
        self.assertTrue(child_unlinked.is_my_parent(root))

        pass
Пример #10
0
 def test_is_root(self):
     root = Node('root')
     child = root.create_child('child')
     self.assertTrue(root.is_root())
     self.assertFalse(child.is_root())
     pass