Sha256: 9870e0119e6b53eaa2974f0a0c5ea9011e76cbacbe9253b0af11af0c6bf5ce86

Contents?: true

Size: 1.87 KB

Versions: 71

Compression:

Stored size: 1.87 KB

Contents

import unittest

from perfect_numbers import classify


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

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")


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")


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.assertRaisesWithMessage(ValueError):
            classify(0)

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

    # Utility functions
    def setUp(self):
        try:
            self.assertRaisesRegex
        except AttributeError:
            self.assertRaisesRegex = self.assertRaisesRegexp

    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")


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

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.138 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.137 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.136 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.135 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.134 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.133 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.132 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.131 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.130 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.129 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.128 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.127 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.126 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.125 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.124 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.123 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.122 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.121 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.120 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py