Commit 47f55b7f authored by Taddeus Kroes's avatar Taddeus Kroes

Merge branch 'master' of kompiler.org:trs

parents 77af3ae1 c09b8a63
......@@ -10,23 +10,6 @@ def nary_node(operator, scope):
else Node(operator, nary_node(operator, scope[:-1]), scope[-1])
def is_prime(n):
"""
Check if the given integer n is a prime number.
"""
if n == 2:
return True
if n < 2 or not n & 1:
return False
for i in xrange(3, int(n ** .5) + 1, 2):
if not divmod(n, i)[1]:
return False
return True
def gcd(a, b):
"""
Return greatest common divisor using Euclid's Algorithm.
......
from src.node import ExpressionNode as N
from src.rules.utils import nary_node, is_prime, least_common_multiple
from src.rules.utils import nary_node, least_common_multiple
from tests.rulestestcase import RulesTestCase, tree
......@@ -15,17 +15,6 @@ class TestRulesUtils(RulesTestCase):
self.assertEqualNodes(nary_node('+', [a, b, c, d]),
N('+', N('+', N('+', a, b), c), d))
def test_is_prime(self):
self.assertTrue(is_prime(2))
self.assertTrue(is_prime(3))
self.assertTrue(is_prime(647))
self.assertFalse(is_prime(0))
self.assertFalse(is_prime(1))
self.assertFalse(is_prime(4))
self.assertFalse(is_prime(9))
self.assertFalse(is_prime(100))
def test_least_common_multiple(self):
self.assertEqual(least_common_multiple(5, 6), 30)
self.assertEqual(least_common_multiple(5, 6, 15), 30)
......
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