1
exercism fetch python perfect-numbers

perfect_numbers_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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import unittest

from perfect_numbers import classify

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


class PerfectNumbersTest(unittest.TestCase):
    def test_smallest_perfect_number(self):
        self.assertIs(classify(6), "perfect")

    def test_medium_perfect_number(self):
        self.assertIs(classify(28), "perfect")

    def test_large_perfect_number(self):
        self.assertIs(classify(33550336), "perfect")

    # Additional tests for this track
    def test_third_perfect_number(self):
        self.assertIs(classify(496), "perfect")

    def test_fourth_perfect_number(self):
        self.assertIs(classify(8128), "perfect")

    def test_sixth_perfect_number(self):
        self.assertIs(classify(8589869056), "perfect")

    def test_seventh_perfect_number(self):
        self.assertIs(classify(137438691328), "perfect")


class AbundantNumbersTest(unittest.TestCase):
    def test_smallest_abundant_number(self):
        self.assertIs(classify(12), "abundant")

    def test_medium_abundant_number(self):
        self.assertIs(classify(30), "abundant")

    def test_large_abundant_number(self):
        self.assertIs(classify(33550335), "abundant")

    # Additional tests for this track
    def test_answer_to_the_ultimate_question_of_life(self):
        self.assertIs(classify(42), "abundant")

    def test_odd_abundant(self):
        self.assertIs(classify(945), "abundant")

    def test_even_abundant(self):
        self.assertIs(classify(20), "abundant")


class DeficientNumbersTest(unittest.TestCase):
    def test_smallest_prime_deficient_number(self):
        self.assertIs(classify(2), "deficient")

    def test_smallest_nonprime_deficient_number(self):
        self.assertIs(classify(4), "deficient")

    def test_medium_deficient_number(self):
        self.assertIs(classify(32), "deficient")

    def test_large_deficient_number(self):
        self.assertIs(classify(33550337), "deficient")

    def test_edge_case(self):
        self.assertIs(classify(1), "deficient")


class InvalidInputsTest(unittest.TestCase):
    def test_zero(self):
        with self.assertRaises(ValueError):
            classify(0)

    def test_negative(self):
        with self.assertRaises(ValueError):
            classify(-1)


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