53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import unittest
|
|
|
|
from grains import (
|
|
square,
|
|
total,
|
|
)
|
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json`
|
|
|
|
|
|
class GrainsTest(unittest.TestCase):
|
|
def test_grains_on_square_1(self):
|
|
self.assertEqual(square(1), 1)
|
|
|
|
def test_grains_on_square_2(self):
|
|
self.assertEqual(square(2), 2)
|
|
|
|
def test_grains_on_square_3(self):
|
|
self.assertEqual(square(3), 4)
|
|
|
|
def test_grains_on_square_4(self):
|
|
self.assertEqual(square(4), 8)
|
|
|
|
def test_grains_on_square_16(self):
|
|
self.assertEqual(square(16), 32768)
|
|
|
|
def test_grains_on_square_32(self):
|
|
self.assertEqual(square(32), 2147483648)
|
|
|
|
def test_grains_on_square_64(self):
|
|
self.assertEqual(square(64), 9223372036854775808)
|
|
|
|
def test_square_0_raises_an_exception(self):
|
|
with self.assertRaises(ValueError) as err:
|
|
square(0)
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
|
|
|
def test_negative_square_raises_an_exception(self):
|
|
with self.assertRaises(ValueError) as err:
|
|
square(-1)
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
|
|
|
def test_square_greater_than_64_raises_an_exception(self):
|
|
with self.assertRaises(ValueError) as err:
|
|
square(65)
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
|
|
|
def test_returns_the_total_number_of_grains_on_the_board(self):
|
|
self.assertEqual(total(), 18446744073709551615)
|