Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
trs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
trs
Commits
77ae42a0
Commit
77ae42a0
authored
12 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added pair iterator.
parent
ecf5d466
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/rules/utils.py
+11
-0
11 additions, 0 deletions
src/rules/utils.py
tests/test_rules_utils.py
+8
-1
8 additions, 1 deletion
tests/test_rules_utils.py
with
19 additions
and
1 deletion
src/rules/utils.py
+
11
−
0
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
]
This diff is collapsed.
Click to expand it.
tests/test_rules_utils.py
+
8
−
1
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
)])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment