2014-06-12 17:55:41 +02:00
|
|
|
"""Tests for the octal exercise
|
|
|
|
|
|
|
|
|
|
Implementation note:
|
2014-06-28 16:19:24 +02:00
|
|
|
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.
|
2014-06-12 17:55:41 +02:00
|
|
|
"""
|
2014-03-18 09:00:03 +01:00
|
|
|
import unittest
|
|
|
|
|
|
2014-06-28 16:19:24 +02:00
|
|
|
from octal import parse_octal
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
class OctalTest(unittest.TestCase):
|
|
|
|
|
def test_octal_1_is_decimal_1(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("1"), 1)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_octal_10_is_decimal_8(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("10"), 8)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_octal_17_is_decimal_15(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("17"), 15)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_octal_130_is_decimal_88(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("130"), 88)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_octal_2047_is_decimal_1063(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("2047"), 1063)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_octal_1234567_is_decimal_342391(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("1234567"), 342391)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_8_is_seen_as_invalid(self):
|
2014-06-28 16:19:24 +02:00
|
|
|
self.assertRaises(ValueError, parse_octal, "8")
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_invalid_octal_is_recognized(self):
|
2014-06-28 16:19:24 +02:00
|
|
|
self.assertRaises(ValueError, parse_octal, "carrot")
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_6789_is_seen_as_invalid(self):
|
2014-06-28 16:19:24 +02:00
|
|
|
self.assertRaises(ValueError, parse_octal, "6789")
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
def test_valid_octal_formatted_string_011_is_decimal_9(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(parse_octal("011"), 9)
|
2014-03-18 09:00:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|