Skip to content

Commit 7878fc0

Browse files
committed
added unit test for extended gcd
1 parent 5d2be00 commit 7878fc0

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

algorithms/math/__init__.py

Whitespace-only changes.

algorithms/tests/test_math.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
from ..math.extended_gcd import extended_gcd
3+
4+
class TestExtendedGCD(unittest.TestCase):
5+
6+
def test_extended_gcd(self):
7+
# Find extended_gcd of 35 and 77
8+
(a,b) = extended_gcd(35, 77)
9+
self.assertIs(35*a + 77*b, 7)
10+
11+
# Find extended_gcd of 15 and 19
12+
(a,b) = extended_gcd(15, 19)
13+
self.assertIs(15*a + 19*b, 1)
14+
15+
# Find extended_gcd of 18 and 9
16+
(a,b) = extended_gcd(18, 9)
17+
self.assertIs(18*a + 9*b, 9)
18+
19+
# Find extended_gcd of 99 and 81
20+
(a,b) = extended_gcd(99, 81)
21+
self.assertIs(99*a + 81*b, 9)
22+
23+
# Find extended_gcd of 50 and 15
24+
(a,b) = extended_gcd(50, 15)
25+
self.assertIs(50*a + 15*b, 5)

0 commit comments

Comments
 (0)