-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lucasoshiro/cleaner_constructor
Cleaner constructor
- Loading branch information
Showing
4 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import pytest | ||
|
||
from itertools import product | ||
from cfg import CFG | ||
|
||
|
||
def test_old_behavior(): | ||
g = CFG( | ||
{'S'}, | ||
{'a', 'b', 'c', 'λ'}, | ||
{('S', 'aSa'), | ||
('S', 'bSb'), | ||
('S', 'cSc'), | ||
('S', 'λ')}, | ||
'S', | ||
'λ' | ||
) | ||
|
||
observed = {x for x in map(''.join, product(*['abc'] * 4)) if g.cyk(x)} | ||
expected = {'aaaa', 'abba', 'acca', 'baab', 'bbbb', 'bccb', 'caac', 'cbbc', 'cccc'} | ||
|
||
assert observed == expected | ||
|
||
def test_with_dict(): | ||
g = CFG( | ||
{'S'}, | ||
{'a', 'b', 'c', 'λ'}, | ||
{'S': ['aSa', 'bSb', 'cSc', 'λ']}, | ||
'S', | ||
'λ' | ||
) | ||
|
||
observed = {x for x in map(''.join, product(*['abc'] * 4)) if g.cyk(x)} | ||
expected = {'aaaa', 'abba', 'acca', 'baab', 'bbbb', 'bccb', 'caac', 'cbbc', 'cccc'} | ||
|
||
assert observed == expected | ||
|
||
def test_without_start_variable_and_null_character(): | ||
g = CFG( | ||
{'S'}, | ||
{'a', 'b', 'c', 'λ'}, | ||
{'S': ['aSa', 'bSb', 'cSc', 'λ']} | ||
) | ||
|
||
observed = {x for x in map(''.join, product(*['abc'] * 4)) if g.cyk(x)} | ||
expected = {'aaaa', 'abba', 'acca', 'baab', 'bbbb', 'bccb', 'caac', 'cbbc', 'cccc'} | ||
|
||
assert observed == expected | ||
|
||
def test_without_variables(): | ||
g = CFG( | ||
terminals={'a', 'b', 'c', 'λ'}, | ||
rules={'S': ['aSa', 'bSb', 'cSc', 'λ']} | ||
) | ||
|
||
observed = {x for x in map(''.join, product(*['abc'] * 4)) if g.cyk(x)} | ||
expected = {'aaaa', 'abba', 'acca', 'baab', 'bbbb', 'bccb', 'caac', 'cbbc', 'cccc'} | ||
|
||
assert observed == expected | ||
|
||
|