1
exercism fetch python prime-factors

prime_factors_test.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import unittest

from prime_factors import prime_factors


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0

class PrimeFactorsTest(unittest.TestCase):
    def test_no_factors(self):
        self.assertEqual(prime_factors(1), [])

    def test_prime_number(self):
        self.assertEqual(prime_factors(2), [2])

    def test_square_of_a_prime(self):
        self.assertEqual(prime_factors(9), [3, 3])

    def test_cube_of_a_prime(self):
        self.assertEqual(prime_factors(8), [2, 2, 2])

    def test_product_of_primes_and_non_primes(self):
        self.assertEqual(prime_factors(12), [2, 2, 3])

    def test_product_of_primes(self):
        self.assertEqual(prime_factors(901255), [5, 17, 23, 461])

    def test_factors_include_a_large_prime(self):
        self.assertEqual(prime_factors(93819012551), [11, 9539, 894119])


if __name__ == '__main__':
    unittest.main()