Skip to content

Commit cff8321

Browse files
dveselovnryoung
authored andcommitted
Initial LCM tests
1 parent fa762b4 commit cff8321

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

algorithms/tests/test_math.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
from ..math.extended_gcd import extended_gcd
3+
from ..math.lcm import lcm
34

45

56
class TestExtendedGCD(unittest.TestCase):
@@ -24,3 +25,16 @@ def test_extended_gcd(self):
2425
# Find extended_gcd of 50 and 15
2526
(a, b) = extended_gcd(50, 15)
2627
self.assertIs(50 * a + 15 * b, 5)
28+
29+
30+
class TestLCM(unittest.TestCase):
31+
def test_lcm(self):
32+
# Find lcm of 16 and 20
33+
r = lcm(16, 20)
34+
self.assertEqual(80, abs(r))
35+
36+
# Find lcm for 20 and 16
37+
r2 = lcm(20, 16)
38+
39+
# Checks that lcm function is commutative
40+
self.assertEqual(r, r2)

0 commit comments

Comments
 (0)