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
a9858f37
Commit
a9858f37
authored
Apr 02, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added utility function to check wether a number divides another number.
parent
6add540a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletion
+16
-1
src/rules/utils.py
src/rules/utils.py
+7
-0
tests/test_rules_utils.py
tests/test_rules_utils.py
+9
-1
No files found.
src/rules/utils.py
View file @
a9858f37
...
@@ -125,3 +125,10 @@ def substitute(f, x, replacement):
...
@@ -125,3 +125,10 @@ def substitute(f, x, replacement):
children
=
map
(
lambda
c
:
substitute
(
c
,
x
,
replacement
),
f
)
children
=
map
(
lambda
c
:
substitute
(
c
,
x
,
replacement
),
f
)
return
N
(
f
.
op
,
*
children
)
return
N
(
f
.
op
,
*
children
)
def
divides
(
m
,
n
):
"""
Check if m | n (m divides n).
"""
return
not
divmod
(
n
,
m
)[
1
]
tests/test_rules_utils.py
View file @
a9858f37
from
src.rules
import
utils
from
src.rules
import
utils
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
from
src.rules.utils
import
least_common_multiple
,
is_fraction
,
partition
,
\
find_variables
,
first_sorted_variable
,
find_variable
,
substitute
find_variables
,
first_sorted_variable
,
find_variable
,
substitute
,
\
divides
from
tests.rulestestcase
import
tree
,
RulesTestCase
from
tests.rulestestcase
import
tree
,
RulesTestCase
...
@@ -57,3 +58,10 @@ class TestRulesUtils(RulesTestCase):
...
@@ -57,3 +58,10 @@ class TestRulesUtils(RulesTestCase):
self
.
assertEqual
(
substitute
(
tree
(
'x2'
),
x
,
a
),
tree
(
'a2'
))
self
.
assertEqual
(
substitute
(
tree
(
'x2'
),
x
,
a
),
tree
(
'a2'
))
self
.
assertEqual
(
substitute
(
tree
(
'y + x + 1'
),
x
,
a
),
self
.
assertEqual
(
substitute
(
tree
(
'y + x + 1'
),
x
,
a
),
tree
(
'y + a + 1'
))
tree
(
'y + a + 1'
))
def
test_divides
(
self
):
self
.
assertTrue
(
divides
(
3
,
3
))
self
.
assertTrue
(
divides
(
2
,
4
))
self
.
assertTrue
(
divides
(
7
,
21
))
self
.
assertFalse
(
divides
(
4
,
2
))
self
.
assertFalse
(
divides
(
2
,
3
))
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