Example #1
0
 def test_dot_1_e(self):
     ''' Testing with 1.e'''
     r = RegexTree("(1.e)")
     s = r.root
     self.assertEqual(
         str(s), str(DotNode(RegexTreeNode('1', []), RegexTreeNode('e',
                                                                   []))))
Example #2
0
 def test_bar_e_1(self):
     ''' Testing with e|1'''
     r = RegexTree("(e|1)")
     s = r.root
     self.assertEqual(
         str(s), str(BarNode(RegexTreeNode('e', []), RegexTreeNode('1',
                                                                   []))))
Example #3
0
 def test_bar_star(self):
     ''' Testing with 0*|1*'''
     r = RegexTree("(0*|1*)")
     s = r.root
     self.assertEqual(
         str(s),
         str(
             BarNode(StarNode(RegexTreeNode('0', [])),
                     StarNode(RegexTreeNode('1', [])))))
Example #4
0
 def test_dot_dot(self):
     ''' Testing with (0.1).0'''
     r = RegexTree("((0.1).0)")
     s = r.root
     self.assertEqual(
         str(s),
         str(
             DotNode(
                 DotNode(RegexTreeNode('0', []), RegexTreeNode('1', [])),
                 RegexTreeNode('0', []))))
Example #5
0
 def test_complete(self):
     ''' Testing with all Nodes'''
     r = RegexTree("((1.(0|1)*).0)")
     s = r.root
     self.assertEqual(
         str(s),
         str(
             DotNode(
                 DotNode(
                     RegexTreeNode('1', []),
                     StarNode(
                         BarNode(RegexTreeNode('0', []),
                                 RegexTreeNode('1', [])))),
                 RegexTreeNode('0', []))))
Example #6
0
 def __init__(self: 'RegexTree', regex: str) -> None:
     """Req: regex must be valid regular expression."""
     # this is where parsing of regex into tree happens
     stack = Stack()
     for char in regex:
         if (char == "0") or (char == "1") or (char == "e"):
             cur_char = RegexTreeNode(char, [])
         elif char == ")":
             exp3 = stack.pop()
             exp2 = stack.pop()
             exp1 = stack.pop()
             stack.pop()
             if exp2 == "|":
                 cur_char = BarNode(exp1, exp3)
             elif exp2 == ".":
                 cur_char = DotNode(exp1, exp3)
         elif char == "*":
             exp = stack.pop()
             cur_char = StarNode(exp)
         else:
             cur_char = char
         stack.push(cur_char)
     self.root = stack.pop()
Example #7
0
 def test_e(self):
     ''' Testing with e.'''
     r = RegexTree("e")
     s = r.root
     self.assertEqual(str(s), str(RegexTreeNode('e', [])))
Example #8
0
 def test_star_0(self):
     ''' Testing with 0*.'''
     r = RegexTree("0*")
     s = r.root
     self.assertEqual(str(s), str(StarNode(RegexTreeNode('0', []))))
Example #9
0
 def test_star_1(self):
     ''' Testing with 1*.'''
     r = RegexTree("1*")
     s = r.root
     self.assertEqual(str(s), str(StarNode(RegexTreeNode('1', []))))
Example #10
0
 def test_star_e(self):
     ''' Testing with e*.'''
     r = RegexTree("e*")
     s = r.root
     self.assertEqual(str(s), str(StarNode(RegexTreeNode('e', []))))
Example #11
0
 def test_0(self):
     ''' Testing with 0.'''
     r = RegexTree("0")
     s = r.root
     self.assertEqual(str(s), str(RegexTreeNode('0', [])))
Example #12
0
 def test_1(self):
     ''' Testing with 1.'''
     r = RegexTree("1")
     s = r.root
     self.assertEqual(str(s), str(RegexTreeNode('1', [])))