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
a9209ec2
Commit
a9209ec2
authored
Feb 17, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added possibility to specify an exponent to ExpressionBase.is_power.
parent
31dc5ca0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
src/node.py
src/node.py
+10
-2
tests/test_node.py
tests/test_node.py
+6
-2
No files found.
src/node.py
View file @
a9209ec2
...
...
@@ -33,6 +33,11 @@ OP_EXPAND = 9
OP_COMMA
=
10
OP_SQRT
=
11
# Goniometry
OP_SIN
=
12
OP_COS
=
13
OP_TAN
=
14
TYPE_MAP
=
{
int
:
TYPE_INTEGER
,
...
...
@@ -112,8 +117,11 @@ class ExpressionBase(object):
def
is_op
(
self
,
op
):
return
not
self
.
is_leaf
and
self
.
op
==
op
def
is_power
(
self
):
return
not
self
.
is_leaf
and
self
.
op
==
OP_POW
def
is_power
(
self
,
exponent
=
None
):
if
self
.
is_leaf
or
self
.
op
!=
OP_POW
:
return
False
return
exponent
==
None
or
self
[
1
]
==
exponent
def
is_nary
(
self
):
return
not
self
.
is_leaf
and
self
.
op
in
[
OP_ADD
,
OP_SUB
,
OP_MUL
]
...
...
tests/test_node.py
View file @
a9209ec2
...
...
@@ -35,8 +35,12 @@ class TestNode(RulesTestCase):
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_leaf
)
def
test_is_power
(
self
):
self
.
assertTrue
(
N
(
'^'
,
*
self
.
l
[:
2
]).
is_power
())
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_power
())
self
.
assertTrue
(
N
(
'^'
,
*
self
.
l
[
2
:]).
is_power
())
self
.
assertFalse
(
N
(
'+'
,
*
self
.
l
[
2
:]).
is_power
())
def
test_is_power_exponent
(
self
):
self
.
assertTrue
(
N
(
'^'
,
*
self
.
l
[
2
:]).
is_power
(
5
))
self
.
assertFalse
(
N
(
'^'
,
*
self
.
l
[
2
:]).
is_power
(
2
))
def
test_is_nary
(
self
):
self
.
assertTrue
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_nary
())
...
...
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