This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnth_prime_test.py
More file actions
65 lines (50 loc) · 1.4 KB
/
Copy pathnth_prime_test.py
File metadata and controls
65 lines (50 loc) · 1.4 KB
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
import unittest
from nth_prime import prime
# Tests adapted from `problem-specifications//canonical-data.json`
def prime_range(n):
"""Returns a list of the first n primes"""
return [prime(i) for i in range(1, n + 1)]
class NthPrimeTest(unittest.TestCase):
def test_first_prime(self):
self.assertEqual(prime(1), 2)
def test_second_prime(self):
self.assertEqual(prime(2), 3)
def test_sixth_prime(self):
self.assertEqual(prime(6), 13)
def test_big_prime(self):
self.assertEqual(prime(10001), 104743)
def test_there_is_no_zeroth_prime(self):
with self.assertRaisesWithMessage(ValueError):
prime(0)
# Additional tests for this track
def test_first_twenty_primes(self):
self.assertEqual(
prime_range(20),
[
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
],
)
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == "__main__":
unittest.main()