Skip to content

Commit

Permalink
fix [^] semantic in nfa_set_nega_char
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylee1997 committed May 20, 2021
1 parent e5c926d commit 60a524a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
__pycache__/
test.py
.gitignore
.idea
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html

3 changes: 3 additions & 0 deletions nfa/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ def nfa_set_nega_char(pair_out):


def char_set_inversion(input_set):
origin = set(input_set)
for i in range(ASCII_COUNT):
c = chr(i)
if c not in input_set:
input_set.add(c)
for c in origin:
input_set.remove(c)


def dodash(input_set):
Expand Down
30 changes: 30 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest
from regex import Regex

class RegexMaterial(object):
def __init__(self, str, pattern, result):
self.str = str
self.pattern = pattern
self.result = result

testLists = []
testLists.append(RegexMaterial("a", "a", True))
testLists.append(RegexMaterial("a", "b+", False))
testLists.append(RegexMaterial("b", "b+", True))
testLists.append(RegexMaterial("ab", "(ab|cd)", True))
testLists.append(RegexMaterial("THISISREGEXTEST", "([A-Z]*|[0-9]+)", True))
testLists.append(RegexMaterial("abbbbb", "[^c]+", True))
testLists.append(RegexMaterial("ccccc", "[^c]+", False))
testLists.append(RegexMaterial("123", "[1-3]+", True))

class TestRegex(unittest.TestCase):
def test(self):
for t in testLists:
print("str is " + t.str + ", pattern is " + t.pattern + ", expected " + str(t.result))
regex = Regex(t.str, t.pattern)
self.assertEqual(regex.match(), t.result)



if __name__ == '__main__':
unittest.main()

0 comments on commit 60a524a

Please sign in to comment.