Sha256: abe1d6d71838c32225f9d45f919e6e3c863e73b6a0c179e19d63353767fc8e14

Contents?: true

Size: 1.19 KB

Versions: 52

Compression:

Stored size: 1.19 KB

Contents

import unittest

from nth_prime import nth_prime


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

class NthPrimeTests(unittest.TestCase):
    def test_first_prime(self):
        self.assertEqual(nth_prime(1), 2)

    def test_second_prime(self):
        self.assertEqual(nth_prime(2), 3)

    def test_sixth_prime(self):
        self.assertEqual(nth_prime(6), 13)

    def test_big_prime(self):
        self.assertEqual(nth_prime(10001), 104743)

    def test_there_is_no_zeroth_prime(self):
        with self.assertRaisesWithMessage(ValueError):
            nth_prime(0)

    # additional track specific test
    def test_first_twenty_primes(self):
        self.assertEqual([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
                          37, 41, 43, 47, 53, 59, 61, 67, 71],
                         [nth_prime(n) for n in range(1, 21)])

    # 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

52 entries across 52 versions & 1 rubygems

Version Path
trackler-2.2.1.140 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.139 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.138 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.137 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.136 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.135 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.134 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.133 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.132 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.131 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.130 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.129 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.128 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.127 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.126 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.125 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.124 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.123 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.122 tracks/python/exercises/nth-prime/nth_prime_test.py
trackler-2.2.1.121 tracks/python/exercises/nth-prime/nth_prime_test.py