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
def test_is_my_child(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_child(root)) self.assertTrue(root.is_my_child(child1)) self.assertTrue(root.is_my_child(child2)) self.assertFalse(root.is_my_child(grandchild)) self.assertFalse(root.is_my_child(root_other)) self.assertFalse(root.is_my_child(child_other)) self.assertFalse(child1.is_my_child(root)) self.assertFalse(child1.is_my_child(child1)) self.assertFalse(child1.is_my_child(child2)) self.assertTrue(child1.is_my_child(grandchild)) self.assertFalse(child1.is_my_child(root_other)) self.assertFalse(child1.is_my_child(child_other)) self.assertFalse(child2.is_my_child(root)) self.assertFalse(child2.is_my_child(child1)) self.assertFalse(child2.is_my_child(child2)) self.assertFalse(child2.is_my_child(grandchild)) self.assertFalse(child2.is_my_child(root_other)) self.assertFalse(child2.is_my_child(child_other)) self.assertFalse(grandchild.is_my_child(root)) self.assertFalse(grandchild.is_my_child(child1)) self.assertFalse(grandchild.is_my_child(child2)) self.assertFalse(grandchild.is_my_child(grandchild)) self.assertFalse(grandchild.is_my_child(root_other)) self.assertFalse(grandchild.is_my_child(child_other)) pass