Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
93d731b2
Verified
Commit
93d731b2
authored
Apr 06, 2020
by
Vladimír Štill
Browse files
test: Add some basic tests for CFG
parent
620bcbaa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
93d731b2
...
...
@@ -4,11 +4,16 @@ PY = $(wildcard *.py)
MYPY
?=
mypy
all
:
check
all
:
test
check
:
$(PY:%=%.mypy)
typecheck
:
$(PY:%=%.mypy)
unit
:
pytest
test
:
typecheck unit
%.mypy
:
%
$(MYPY)
--check-untyped-defs
--warn-redundant-casts
--warn-unused-ignores
--warn-return-any
$<
$(MYPY)
--
type
check-untyped-defs
--warn-redundant-casts
--warn-unused-ignores
--warn-return-any
$<
.PHONY
:
%.mypy check all
.PHONY
:
%.mypy
type
check
test unit
all
fja/tests/__init__.py
0 → 100644
View file @
93d731b2
fja/tests/cfl/__init__.py
0 → 100644
View file @
93d731b2
fja/tests/cfl/cfg_test.py
0 → 100644
View file @
93d731b2
from
...common
import
Nonterminal
,
Terminal
from
...
import
cfl
from
copy
import
deepcopy
A
=
Nonterminal
(
"A"
)
B
=
Nonterminal
(
"B"
)
C
=
Nonterminal
(
"C"
)
a
=
Terminal
(
"a"
)
b
=
Terminal
(
"b"
)
Rules
=
cfl
.
CFG
.
Rules
rules0
:
Rules
=
dict
()
g0
=
cfl
.
CFG
({
A
},
{
a
,
b
},
rules0
,
A
)
rules1
:
Rules
=
{
A
:
{(
a
,),
(
a
,
A
),
(
b
,
B
),
(
b
,)},
B
:
{(
b
,),
(
b
,
B
)}}
g1
=
cfl
.
CFG
({
A
,
B
},
{
a
,
b
},
rules1
,
A
)
rules2
:
Rules
=
{
A
:
{(
a
,),
(
a
,
A
),
(
b
,
B
)},
B
:
{(
b
,
B
),
()}}
g2
=
cfl
.
CFG
({
A
,
B
},
{
a
,
b
},
rules2
,
A
)
def
test_empty
():
assert
g0
.
is_empty
()
def
test_basics
():
assert
g1
.
init
==
A
assert
g1
.
terminals
==
{
a
,
b
}
assert
g1
.
nonterminals
==
{
A
,
B
}
assert
g1
.
rules
==
rules1
collected_prods
=
set
(
g1
.
productions
())
assert
collected_prods
==
{(
src
,
dst
)
for
src
,
prods
in
rules1
.
items
()
for
dst
in
prods
}
def
test_generates
():
def
go
(
g
):
assert
g
.
generates
(
"a"
)
assert
g
.
generates
(
"b"
)
assert
g
.
generates
(
"aa"
)
assert
g
.
generates
(
"ab"
)
assert
g
.
generates
(
"abbb"
)
assert
g
.
generates
(
"aabbb"
)
assert
not
g
.
generates
(
""
)
assert
not
g
.
generates
(
"ba"
)
go
(
g1
)
go
(
g2
)
def
test_remove_eps
():
g
=
g2
.
epsilon_normal_form
()
assert
g
.
init
==
g1
.
init
assert
g
.
terminals
==
g1
.
terminals
assert
g
.
nonterminals
==
g1
.
nonterminals
assert
g
.
rules
==
g1
.
rules
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment