forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrains_test.py
More file actions
51 lines (34 loc) · 1.31 KB
/
Copy pathgrains_test.py
File metadata and controls
51 lines (34 loc) · 1.31 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
import unittest
from grains import square, total
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
class GrainsTest(unittest.TestCase):
def test_1(self):
self.assertEqual(square(1), 1)
def test_2(self):
self.assertEqual(square(2), 2)
def test_3(self):
self.assertEqual(square(3), 4)
def test_4(self):
self.assertEqual(square(4), 8)
def test_16(self):
self.assertEqual(square(16), 32768)
def test_32(self):
self.assertEqual(square(32), 2147483648)
def test_64(self):
self.assertEqual(square(64), 9223372036854775808)
def test_square_0_raises_an_exception(self):
with self.assertRaisesWithMessage(ValueError):
square(0)
def test_negative_square_raises_an_exception(self):
with self.assertRaisesWithMessage(ValueError):
square(-1)
def test_square_greater_than_64_raises_an_exception(self):
with self.assertRaisesWithMessage(ValueError):
square(65)
def test_returns_the_total_number_of_grains_on_the_board(self):
self.assertEqual(total(), 18446744073709551615)
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == "__main__":
unittest.main()