diff --git a/.gitignore b/.gitignore index df2b903..563155a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,13 @@ __pycache__/ -test.py \ No newline at end of file +.gitignore +.idea +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html + diff --git a/nfa/construction.py b/nfa/construction.py index 3984b69..ce0cb13 100644 --- a/nfa/construction.py +++ b/nfa/construction.py @@ -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): diff --git a/test/test.py b/test/test.py new file mode 100644 index 0000000..23b7d86 --- /dev/null +++ b/test/test.py @@ -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() \ No newline at end of file