2013-08-08 11:54:53 -05:00
|
|
|
import unittest
|
|
|
|
|
|
2017-04-11 06:05:52 -04:00
|
|
|
from grains import (
|
|
|
|
|
on_square,
|
|
|
|
|
total_after,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2014-02-22 10:55:33 +08:00
|
|
|
|
2017-11-05 23:06:52 +00:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
|
|
|
|
|
|
2013-08-08 11:54:53 -05:00
|
|
|
class GrainsTest(unittest.TestCase):
|
|
|
|
|
def test_square_1(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(1), 1)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_2(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(2), 2)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_3(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(3), 4)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_4(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(4), 8)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_16(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(16), 32768)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_32(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(32), 2147483648)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
|
|
|
|
def test_square_64(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(on_square(64), 9223372036854775808)
|
2013-08-08 11:54:53 -05:00
|
|
|
|
2017-04-11 06:05:52 -04:00
|
|
|
def test_square_0_raises_exception(self):
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
on_square(0)
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
total_after(0)
|
|
|
|
|
|
|
|
|
|
def test_square_negative_raises_exception(self):
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
on_square(-1)
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
total_after(-1)
|
|
|
|
|
|
|
|
|
|
def test_square_gt_64_raises_exception(self):
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
on_square(65)
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
total_after(65)
|
|
|
|
|
|
2017-11-05 23:06:52 +00:00
|
|
|
def test_total(self):
|
|
|
|
|
self.assertEqual(total_after(64), 18446744073709551615)
|
|
|
|
|
|
2016-11-29 09:44:47 +01:00
|
|
|
|
2013-08-08 11:54:53 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|