Exemplo n.º 1
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
Exemplo n.º 2
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