Commit a9858f37 authored by Taddeus Kroes's avatar Taddeus Kroes

Added utility function to check wether a number divides another number.

parent 6add540a
......@@ -125,3 +125,10 @@ def substitute(f, x, replacement):
children = map(lambda c: substitute(c, x, replacement), f)
return N(f.op, *children)
def divides(m, n):
"""
Check if m | n (m divides n).
"""
return not divmod(n, m)[1]
from src.rules import utils
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
......@@ -57,3 +58,10 @@ class TestRulesUtils(RulesTestCase):
self.assertEqual(substitute(tree('x2'), x, a), tree('a2'))
self.assertEqual(substitute(tree('y + x + 1'), x, a),
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))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment