Moved solutions till 35 to Python.
This commit is contained in:
@@ -11,6 +11,8 @@ try:
|
||||
from .lib_misc import collatz_sequence_length
|
||||
from .lib_misc import factorial
|
||||
from .lib_misc import proper_divisors, sum_proper_divisors
|
||||
from .lib_misc import permutations
|
||||
from .lib_misc import gcd
|
||||
except ModuleNotFoundError:
|
||||
from lib_misc import is_palindrome_integer
|
||||
from lib_misc import is_palindrome_string
|
||||
@@ -23,6 +25,8 @@ except ModuleNotFoundError:
|
||||
from lib_misc import collatz_sequence_length
|
||||
from lib_misc import factorial
|
||||
from lib_misc import proper_divisors, sum_proper_divisors
|
||||
from lib_misc import permutations
|
||||
from lib_misc import gcd
|
||||
|
||||
|
||||
class TestPrimeMethods(unittest.TestCase):
|
||||
@@ -95,6 +99,38 @@ class TestPrimeMethods(unittest.TestCase):
|
||||
self.assertEqual(sum_proper_divisors(220), 284)
|
||||
self.assertEqual(sum_proper_divisors(284), 220)
|
||||
|
||||
def test_permutations(self):
|
||||
from itertools import permutations as std_permutations
|
||||
test_list = []
|
||||
p1 = list(map(tuple, permutations(test_list)))
|
||||
p2 = list(std_permutations(test_list))
|
||||
self.assertEqual(p1, p2)
|
||||
|
||||
test_list = [1]
|
||||
p1 = list(map(tuple, permutations(test_list)))
|
||||
p2 = list(std_permutations(test_list))
|
||||
self.assertEqual(p1, p2)
|
||||
|
||||
test_list = [1, 2, 3]
|
||||
p1 = list(map(tuple, permutations(test_list)))
|
||||
p2 = list(std_permutations(test_list))
|
||||
self.assertEqual(p1, p2)
|
||||
|
||||
test_list = [1, 2, 3, 4, 5, 6]
|
||||
p1 = list(map(tuple, permutations(test_list)))
|
||||
p2 = list(std_permutations(test_list))
|
||||
self.assertEqual(p1, p2)
|
||||
|
||||
test_list = "abc"
|
||||
p1 = list(map(tuple, permutations(test_list)))
|
||||
p2 = list(std_permutations(test_list))
|
||||
self.assertEqual(p1, p2)
|
||||
|
||||
def test_gcd(self):
|
||||
self.assertEqual(gcd(3, 2), 1)
|
||||
self.assertEqual(gcd(15, 6), 3)
|
||||
self.assertEqual(gcd(6, 15), 3)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user