Sha256: 10701d73faeef211364b21654fb2a444041ce3fd42ff98999cea0c4b6d99c93c

Contents?: true

Size: 1.76 KB

Versions: 68

Compression:

Stored size: 1.76 KB

Contents

import unittest

from grains import (
    on_square,
    total_after,
)


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class GrainsTest(unittest.TestCase):
    def test_square_1(self):
        self.assertEqual(on_square(1), 1)

    def test_square_2(self):
        self.assertEqual(on_square(2), 2)

    def test_square_3(self):
        self.assertEqual(on_square(3), 4)

    def test_square_4(self):
        self.assertEqual(on_square(4), 8)

    def test_square_16(self):
        self.assertEqual(on_square(16), 32768)

    def test_square_32(self):
        self.assertEqual(on_square(32), 2147483648)

    def test_square_64(self):
        self.assertEqual(on_square(64), 9223372036854775808)

    def test_square_0_raises_exception(self):
        with self.assertRaisesWithMessage(ValueError):
            on_square(0)
        with self.assertRaisesWithMessage(ValueError):
            total_after(0)

    def test_square_negative_raises_exception(self):
        with self.assertRaisesWithMessage(ValueError):
            on_square(-1)
        with self.assertRaisesWithMessage(ValueError):
            total_after(-1)

    def test_square_gt_64_raises_exception(self):
        with self.assertRaisesWithMessage(ValueError):
            on_square(65)
        with self.assertRaisesWithMessage(ValueError):
            total_after(65)

    def test_total(self):
        self.assertEqual(total_after(64), 18446744073709551615)

    # Utility functions
    def setUp(self):
        try:
            self.assertRaisesRegex
        except AttributeError:
            self.assertRaisesRegex = self.assertRaisesRegexp

    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")


if __name__ == '__main__':
    unittest.main()

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.138 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.137 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.136 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.135 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.134 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.133 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.132 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.131 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.130 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.129 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.128 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.127 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.126 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.125 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.124 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.123 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.122 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.121 tracks/python/exercises/grains/grains_test.py
trackler-2.2.1.120 tracks/python/exercises/grains/grains_test.py