2023-07-15 15:27:31 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/grains/canonical-data.json
|
2023-09-27 23:36:49 +02:00
|
|
|
# File last updated on 2023-09-27
|
2023-07-15 15:27:31 -07:00
|
|
|
|
2013-08-08 11:54:53 -05:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from grains import (
|
|
|
|
|
square,
|
|
|
|
|
total,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2019-10-25 07:01:05 -07:00
|
|
|
|
2013-08-08 11:54:53 -05:00
|
|
|
class GrainsTest(unittest.TestCase):
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_1(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(1), 1)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_2(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(2), 2)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_3(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(3), 4)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_4(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(4), 8)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_16(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(16), 32768)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_32(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(32), 2147483648)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_grains_on_square_64(self):
|
2019-05-26 13:11:24 -07:00
|
|
|
self.assertEqual(square(64), 9223372036854775808)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2023-09-27 23:36:49 +02:00
|
|
|
def test_square_0_is_invalid(self):
|
2021-10-25 14:05:13 -07:00
|
|
|
with self.assertRaises(ValueError) as err:
|
2019-05-26 13:11:24 -07:00
|
|
|
square(0)
|
2021-10-25 14:05:13 -07:00
|
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
|
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
2017-04-11 06:05:52 -04:00
|
|
|
|
2023-09-27 23:36:49 +02:00
|
|
|
def test_negative_square_is_invalid(self):
|
2021-10-25 14:05:13 -07:00
|
|
|
with self.assertRaises(ValueError) as err:
|
2019-05-26 13:11:24 -07:00
|
|
|
square(-1)
|
2021-10-25 14:05:13 -07:00
|
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
|
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
2017-04-11 06:05:52 -04:00
|
|
|
|
2023-09-27 23:36:49 +02:00
|
|
|
def test_square_greater_than_64_is_invalid(self):
|
2021-10-25 14:05:13 -07:00
|
|
|
with self.assertRaises(ValueError) as err:
|
2019-05-26 13:11:24 -07:00
|
|
|
square(65)
|
2021-10-25 14:05:13 -07:00
|
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
|
|
|
self.assertEqual(err.exception.args[0], "square must be between 1 and 64")
|
2017-04-11 06:05:52 -04:00
|
|
|
|
2019-10-25 07:01:05 -07:00
|
|
|
def test_returns_the_total_number_of_grains_on_the_board(self):
|
|
|
|
|
self.assertEqual(total(), 18446744073709551615)
|