Sha256: 359ca67ce7f1e85b227223334cbc9e9a79069f2e0b8028a37b41069a448aa396

Contents?: true

Size: 1.67 KB

Versions: 83

Compression:

Stored size: 1.67 KB

Contents

"""Tests for the octal exercise

Implementation note:
If the string supplied to parse_octal cannot be parsed as an octal number
your program should raise a ValueError with a meaningful error message.
"""
import unittest

from octal import parse_octal


class OctalTest(unittest.TestCase):
    def test_octal_1_is_decimal_1(self):
        self.assertEqual(parse_octal("1"), 1)

    def test_octal_10_is_decimal_8(self):
        self.assertEqual(parse_octal("10"), 8)

    def test_octal_17_is_decimal_15(self):
        self.assertEqual(parse_octal("17"), 15)

    def test_octal_130_is_decimal_88(self):
        self.assertEqual(parse_octal("130"), 88)

    def test_octal_2047_is_decimal_1063(self):
        self.assertEqual(parse_octal("2047"), 1063)

    def test_octal_1234567_is_decimal_342391(self):
        self.assertEqual(parse_octal("1234567"), 342391)

    def test_8_is_seen_as_invalid(self):
        with self.assertRaisesWithMessage(ValueError):
            parse_octal("8")

    def test_invalid_octal_is_recognized(self):
        with self.assertRaisesWithMessage(ValueError):
            parse_octal("carrot")

    def test_6789_is_seen_as_invalid(self):
        with self.assertRaisesWithMessage(ValueError):
            parse_octal("6789")

    def test_valid_octal_formatted_string_011_is_decimal_9(self):
        self.assertEqual(parse_octal("011"), 9)

    # 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

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.179 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.178 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.177 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.176 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.175 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.174 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.173 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.172 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.171 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.170 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.169 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.167 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.166 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.165 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.164 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.163 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.162 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.161 tracks/python/exercises/octal/octal_test.py
trackler-2.2.1.160 tracks/python/exercises/octal/octal_test.py