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.180 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.179 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.178 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.177 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.176 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.175 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.174 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.173 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.172 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.171 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.170 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.169 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.167 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.166 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.165 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.164 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.163 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.162 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.161 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py
trackler-2.2.1.160 tracks/python/exercises/perfect-numbers/perfect_numbers_test.py