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
77ae42a0
Commit
77ae42a0
authored
May 16, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pair iterator.
parent
ecf5d466
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
src/rules/utils.py
src/rules/utils.py
+11
-0
tests/test_rules_utils.py
tests/test_rules_utils.py
+8
-1
No files found.
src/rules/utils.py
View file @
77ae42a0
...
...
@@ -194,3 +194,14 @@ def evals_to_numeric(node):
return
node
.
op
in
(
OP_ADD
,
OP_MUL
,
OP_DIV
,
OP_POW
,
OP_SQRT
)
\
and
all
(
map
(
evals_to_numeric
,
node
))
def
iter_pairs
(
list_iterable
):
"""
Iterate over a list iterable in left-right pairs.
"""
if
len
(
list_iterable
)
<
2
:
raise
StopIteration
for
i
,
left
in
enumerate
(
list_iterable
[:
-
1
]):
yield
left
,
list_iterable
[
i
+
1
]
tests/test_rules_utils.py
View file @
77ae42a0
from
src.rules
import
utils
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
find_variables
,
first_sorted_variable
,
find_variable
,
substitute
,
\
divides
,
dividers
,
is_prime
,
prime_dividers
,
evals_to_numeric
divides
,
dividers
,
is_prime
,
prime_dividers
,
evals_to_numeric
,
\
iter_pairs
from
tests.rulestestcase
import
tree
,
RulesTestCase
...
...
@@ -103,3 +104,9 @@ class TestRulesUtils(RulesTestCase):
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'int 1'
)))
self
.
assertFalse
(
evals_to_numeric
(
tree
(
'int a'
)))
self
.
assertTrue
(
evals_to_numeric
(
tree
(
'sqrt 1'
)))
def
test_iter_pairs
(
self
):
self
.
assertEqual
(
list
(
iter_pairs
([
1
])),
[])
self
.
assertEqual
(
list
(
iter_pairs
([
1
,
2
])),
[(
1
,
2
)])
self
.
assertEqual
(
list
(
iter_pairs
([
1
,
2
,
3
])),
[(
1
,
2
),
(
2
,
3
)])
self
.
assertEqual
(
list
(
iter_pairs
([
1
,
2
,
3
,
4
])),
[(
1
,
2
),
(
2
,
3
),
(
3
,
4
)])
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