Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
a836452c
Commit
a836452c
authored
Jan 14, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of kompiler.org:trs
parents
6bc98dd5
af1fd43e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
8 deletions
+60
-8
src/possibilities.py
src/possibilities.py
+0
-1
tests/rulestestcase.py
tests/rulestestcase.py
+2
-2
tests/test_node.py
tests/test_node.py
+14
-0
tests/test_possibilities.py
tests/test_possibilities.py
+42
-0
tests/test_rules_numerics.py
tests/test_rules_numerics.py
+2
-4
tests/test_rules_poly.py
tests/test_rules_poly.py
+0
-1
No files found.
src/possibilities.py
View file @
a836452c
...
...
@@ -22,7 +22,6 @@ class Possibility(object):
return
'<Possibility root="%s" handler=%s args=%s>'
\
%
(
self
.
root
,
self
.
handler
.
func_name
,
self
.
args
)
# TODO: Add unit tests
def
__eq__
(
self
,
other
):
return
self
.
handler
==
other
.
handler
\
and
hash
(
self
.
root
)
==
hash
(
other
.
root
)
\
...
...
tests/rulestestcase.py
View file @
a836452c
...
...
@@ -10,9 +10,9 @@ class RulesTestCase(unittest.TestCase):
for
p
,
e
in
zip
(
possibilities
,
expected
):
self
.
assertEqual
(
p
.
root
,
e
.
root
)
if
p
.
args
==
None
:
if
p
.
args
==
None
:
# pragma: nocover
self
.
assertIsNone
(
e
.
args
)
elif
e
.
args
==
None
:
elif
e
.
args
==
None
:
# pragma: nocover
self
.
assertIsNone
(
p
.
args
)
else
:
for
pair
in
zip
(
p
.
args
,
e
.
args
):
...
...
tests/test_node.py
View file @
a836452c
...
...
@@ -8,6 +8,20 @@ class TestNode(unittest.TestCase):
def
setUp
(
self
):
self
.
l
=
[
L
(
1
),
N
(
'*'
,
L
(
2
),
L
(
3
)),
L
(
4
),
L
(
5
)]
def
test___lt__
(
self
):
self
.
assertTrue
(
L
(
1
)
<
L
(
2
))
self
.
assertFalse
(
L
(
1
)
<
L
(
1
))
self
.
assertFalse
(
L
(
2
)
<
L
(
1
))
self
.
assertTrue
(
L
(
2
)
<
N
(
'+'
,
L
(
1
),
L
(
2
)))
self
.
assertFalse
(
N
(
'+'
,
L
(
1
),
L
(
2
))
<
L
(
1
))
self
.
assertTrue
(
N
(
'^'
,
L
(
'a'
),
L
(
2
))
<
N
(
'^'
,
L
(
'a'
),
L
(
3
)))
self
.
assertTrue
(
N
(
'^'
,
L
(
2
),
L
(
'a'
))
<
N
(
'^'
,
L
(
3
),
L
(
'a'
)))
self
.
assertTrue
(
N
(
'*'
,
L
(
2
),
N
(
'^'
,
L
(
'a'
),
L
(
'b'
)))
<
N
(
'*'
,
L
(
3
),
N
(
'^'
,
L
(
'a'
),
L
(
'b'
))))
self
.
assertFalse
(
N
(
'^'
,
L
(
'a'
),
L
(
3
))
<
N
(
'^'
,
L
(
'a'
),
L
(
2
)))
def
test_is_power_true
(
self
):
self
.
assertTrue
(
N
(
'^'
,
*
self
.
l
[:
2
]).
is_power
())
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_power
())
...
...
tests/test_possibilities.py
0 → 100644
View file @
a836452c
import
unittest
from
src.possibilities
import
MESSAGES
,
Possibility
as
P
,
filter_duplicates
from
tests.test_rules_poly
import
tree
def
dummy_handler
(
root
,
args
):
# pragma: nocover
pass
def
dummy_handler_msg
(
root
,
args
):
# pragma: nocover
pass
MESSAGES
[
dummy_handler_msg
]
=
'foo {1} + {2} bar'
class
TestPossibilities
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
l1
,
self
.
l2
=
self
.
n
=
tree
(
'1 + 2'
)
self
.
p0
=
P
(
self
.
n
,
dummy_handler
,
(
self
.
l1
,
self
.
l2
))
self
.
p1
=
P
(
self
.
n
,
dummy_handler_msg
,
(
self
.
l1
,
self
.
l2
))
def
test___str__
(
self
):
self
.
assertEqual
(
str
(
self
.
p0
),
'<Possibility root="1 + 2" handler=dummy_handler args=(1, 2)>'
)
self
.
assertEqual
(
str
(
self
.
p1
),
'foo 1 + 2 bar'
)
def
test___repr__
(
self
):
self
.
assertEqual
(
repr
(
self
.
p0
),
'<Possibility root="1 + 2" handler=dummy_handler args=(1, 2)>'
)
def
test___eq__
(
self
):
assert
self
.
p0
==
P
(
self
.
n
,
dummy_handler
,
(
self
.
l1
,
self
.
l2
))
assert
self
.
p0
!=
self
.
p1
def
test_filter_duplicates
(
self
):
self
.
assertEqual
(
filter_duplicates
([]),
[])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
]),
[
1
,
2
])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
,
2
]),
[
1
,
2
])
self
.
assertEqual
(
filter_duplicates
([
1
,
2
,
3
,
2
]),
[
1
,
2
,
3
])
tests/test_rules_numerics.py
View file @
a836452c
...
...
@@ -58,10 +58,8 @@ class TestRulesNumerics(RulesTestCase):
self
.
assertEqual
(
divide_numerics
(
i3
/
f2
,
(
3
,
2.0
)),
1.5
)
self
.
assertEqual
(
divide_numerics
(
f3
/
f2
,
(
3.0
,
2.0
)),
1.5
)
def
test_add_numerics
(
self
):
l0
,
l1
=
tree
(
'1,2'
)
self
.
assertEqual
(
add_numerics
(
l0
+
l1
,
(
l0
,
l1
,
1
,
2
)),
3
)
def
test_add_numerics
(
self
):
l0
,
a
,
l1
=
tree
(
'1,a,2'
)
self
.
assertEqual
(
add_numerics
(
l0
+
l1
,
(
l0
,
l1
,
1
,
2
)),
3
)
self
.
assertEqual
(
add_numerics
(
l0
+
a
+
l1
,
(
l0
,
l1
,
1
,
2
)),
L
(
3
)
+
a
)
tests/test_rules_poly.py
View file @
a836452c
from
src.rules.poly
import
match_combine_polynomes
,
combine_polynomes
from
src.rules.numerics
import
add_numerics
from
src.possibilities
import
Possibility
as
P
from
src.node
import
ExpressionLeaf
as
L
from
src.parser
import
Parser
from
tests.parser
import
ParserWrapper
from
tests.rulestestcase
import
RulesTestCase
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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