def incorporate(pattern, trie): # incorporate takes a pattern and incorporates it as another branch # of a preexisting trie. # if the trie is empty, add a node. if trie.O == []: x = trie_methods.name() trie.node(x) # set the current node to the root. x = trie_methods.root(trie) # iterate through the pattern. for s in pattern: # if there is an existing edge matching the symbol, select it. if trie_methods.edge_exists(s, x, trie): f = trie_methods.select(s, x, trie) # update the current node to that edge's codomain. x = trie.cod[f] else: # if there is not an existing edge, # create an edge with the current symbol. y = trie_methods.name() trie.node(y) e = trie_methods.name() trie.edge(e, x, y, s) # update the current node to that edge's codomain. x = trie.cod[e] return trie
def auto_name(self): trie = graph.Graph() trie.node('A') trie.node('B') f = trie_methods.name() trie.edge(f, 'A', 'B', 't') self.assertIn(f, trie.A) self.assertTrue(trie.dom[f] == 'A') self.assertTrue(trie.cod[f] == 'B') self.assertTrue(trie.sym[f] == 't')
def test_normal(self): s = trie_methods.name() self.assertIsInstance(s, str) self.assertEqual(len(s), 6)
def test_auto(self): trie = graph.Graph() n = trie_methods.name() trie.node(n) self.assertIn(n, trie.O)