Esempio n. 1
0
 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)
Esempio n. 2
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.')