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
b63b5130
Commit
b63b5130
authored
Feb 16, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added negation counter to strict equivalence check and added 'replace' function to Scope class.
parent
105cd269
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
22 deletions
+12
-22
src/node.py
src/node.py
+8
-6
tests/test_node.py
tests/test_node.py
+4
-16
No files found.
src/node.py
View file @
b63b5130
...
...
@@ -170,10 +170,8 @@ class ExpressionNode(Node, ExpressionBase):
"""
Check strict equivalence.
"""
if
isinstance
(
other
,
ExpressionNode
):
return
self
.
op
==
other
.
op
and
self
.
nodes
==
other
.
nodes
return
False
return
isinstance
(
other
,
ExpressionNode
)
and
self
.
op
==
other
.
op
\
and
self
.
negated
==
other
.
negated
and
self
.
nodes
==
other
.
nodes
def
substitute
(
self
,
old_child
,
new_child
):
self
.
nodes
[
self
.
nodes
.
index
(
old_child
)]
=
new_child
...
...
@@ -267,7 +265,7 @@ class ExpressionNode(Node, ExpressionBase):
s0
=
Scope
(
self
)
s1
=
set
(
Scope
(
other
))
# Scopes sould be of equal size
# Scopes s
h
ould be of equal size
if
len
(
s0
)
!=
len
(
s1
):
return
False
...
...
@@ -308,7 +306,8 @@ class ExpressionLeaf(Leaf, ExpressionBase):
if
other_type
in
TYPE_MAP
:
return
TYPE_MAP
[
other_type
]
==
self
.
type
and
self
.
value
==
other
return
other
.
type
==
self
.
type
and
self
.
value
==
other
.
value
return
self
.
negated
==
other
.
negated
and
self
.
type
==
other
.
type
\
and
self
.
value
==
other
.
value
def
equals
(
self
,
other
):
"""
...
...
@@ -373,6 +372,9 @@ class Scope(object):
raise
ValueError
(
'Node "%s" is not in the scope of "%s".'
%
(
node
,
self
.
node
))
def
replace
(
self
,
node
,
replacement
):
self
.
remove
(
node
,
replacement
=
replacement
)
def
as_nary_node
(
self
):
return
nary_node
(
self
.
node
.
value
,
self
.
nodes
)
...
...
tests/test_node.py
View file @
b63b5130
...
...
@@ -30,22 +30,10 @@ class TestNode(RulesTestCase):
self
.
assertTrue
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_op
(
OP_ADD
))
self
.
assertFalse
(
N
(
'-'
,
*
self
.
l
[:
2
]).
is_op
(
OP_ADD
))
def
test_is_op_or_negated
(
self
):
self
.
assertTrue
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertTrue
(
N
(
'-'
,
N
(
'+'
,
*
self
.
l
[:
2
])).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
N
(
'-'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
self
.
l
[
0
].
is_op_or_negated
(
OP_ADD
))
def
test_is_leaf
(
self
):
self
.
assertTrue
(
L
(
2
).
is_leaf
)
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_leaf
)
def
test_is_leaf_or_negated
(
self
):
self
.
assertTrue
(
L
(
2
).
is_leaf_or_negated
())
self
.
assertTrue
(
N
(
'-'
,
L
(
2
)).
is_leaf_or_negated
())
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_leaf_or_negated
())
self
.
assertFalse
(
N
(
'-'
,
N
(
'+'
,
*
self
.
l
[:
2
])).
is_leaf_or_negated
())
def
test_is_power
(
self
):
self
.
assertTrue
(
N
(
'^'
,
*
self
.
l
[:
2
]).
is_power
())
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_power
())
...
...
@@ -185,14 +173,14 @@ class TestNode(RulesTestCase):
self
.
scope
.
remove
(
self
.
cd
)
self
.
assertEqual
(
self
.
scope
.
nodes
,
[
self
.
a
,
self
.
b
])
def
test_scope_remove_replace
(
self
):
self
.
scope
.
remove
(
self
.
cd
,
self
.
f
)
self
.
assertEqual
(
self
.
scope
.
nodes
,
[
self
.
a
,
self
.
b
,
self
.
f
])
def
test_scope_remove_error
(
self
):
with
self
.
assertRaises
(
ValueError
):
self
.
scope
.
remove
(
self
.
f
)
def
test_scope_replace
(
self
):
self
.
scope
.
replace
(
self
.
cd
,
self
.
f
)
self
.
assertEqual
(
self
.
scope
.
nodes
,
[
self
.
a
,
self
.
b
,
self
.
f
])
def
test_nary_node
(
self
):
a
,
b
,
c
,
d
=
tree
(
'a,b,c,d'
)
...
...
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