예제 #1
0
 def test_expand_excludes_terminals(self):
     tree = ParseTree(self.A)
     self.assertEqual(frontier_values(tree), [self.A])
     tree.expand([self.B, "hello", self.B])
     self.assertEqual(frontier_values(tree), [self.B, self.B])
     tree.frontier[1].expand([self.A, "world", self.A])
     self.assertEqual(frontier_values(tree), [self.B, self.A, self.A])
예제 #2
0
 def test_expand_propagates_to_ancestors(self):
     tree = ParseTree(self.A)
     self.assertEqual(frontier_values(tree), [self.A])
     tree.expand([self.B, self.B])
     self.assertEqual(frontier_values(tree), [self.B, self.B])
     tree.frontier[1].expand([self.A, self.B, self.A])
     self.assertEqual(frontier_values(tree),
                      [self.B, self.A, self.B, self.A])
예제 #3
0
 def test_expand_empty_production_shrinks_frontier(self):
     tree = ParseTree(self.A)
     self.assertEqual(frontier_values(tree), [self.A])
     tree.expand(())
     self.assertEqual(frontier_values(tree), [])