def test_add_remove_tree(self): forest = Forest() self.assertEqual(forest.n_children(), 0) node = Tree(3) forest.add_tree(node) self.assertEqual(forest.n_children(), 1) self.assertRaises(Exception, forest.add_tree, *(1, )) forest.remove_tree(0) self.assertEqual(forest.n_children(), 0)
def test_depth(self): # # Generate forest # forest = Forest([Tree(2), Tree(2)]) # # Split tree 0 three times # tree = forest.get_child(0) for dummy in range(3): tree.split() tree = tree.get_child(0) # Check that depth is 3 self.assertEqual(forest.depth(), 3) # Remove split tree and verify that depth is 0 forest.remove_tree(0) self.assertEqual(forest.depth(), 0)
def test_in_forest(self): # # Initialize forest with node # node = Tree(n_children=2) Forest([node]) self.assertTrue(node.in_forest(), 'Node should be in forest') # # Initialize empty forest # node = Tree(n_children=2) forest = Forest() # Node should not be in there self.assertFalse(node.in_forest(), 'Node should not be in a forest.') # Add node: NOW it's in the forest. forest.add_tree(node) self.assertTrue(node.in_forest(), 'Node should be in a forest.') # Remove node: it should no longer be there. forest.remove_tree(node.get_node_position()) self.assertFalse(node.in_forest(), 'Node should no longer be in the forest.')