Files
python/exercises/practice/say/say_test.py

86 lines
2.6 KiB
Python
Raw Normal View History

# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/say/canonical-data.json
# File last updated on 2023-07-15
2015-11-13 11:09:09 +01:00
import unittest
from say import (
say,
)
2015-11-13 11:09:09 +01:00
2015-11-13 11:09:09 +01:00
class SayTest(unittest.TestCase):
def test_zero(self):
self.assertEqual(say(0), "zero")
2015-11-13 11:09:09 +01:00
def test_one(self):
self.assertEqual(say(1), "one")
2015-11-13 11:09:09 +01:00
def test_fourteen(self):
self.assertEqual(say(14), "fourteen")
2015-11-13 11:09:09 +01:00
def test_twenty(self):
self.assertEqual(say(20), "twenty")
2015-11-13 11:09:09 +01:00
def test_twenty_two(self):
self.assertEqual(say(22), "twenty-two")
2015-11-13 11:09:09 +01:00
2022-12-02 17:39:30 +01:00
def test_thirty(self):
self.assertEqual(say(30), "thirty")
def test_ninety_nine(self):
self.assertEqual(say(99), "ninety-nine")
2015-11-13 11:09:09 +01:00
def test_one_hundred(self):
self.assertEqual(say(100), "one hundred")
2015-11-13 11:09:09 +01:00
def test_one_hundred_twenty_three(self):
self.assertEqual(say(123), "one hundred twenty-three")
2015-11-13 11:09:09 +01:00
2022-12-02 17:39:30 +01:00
def test_two_hundred(self):
self.assertEqual(say(200), "two hundred")
def test_nine_hundred_ninety_nine(self):
self.assertEqual(say(999), "nine hundred ninety-nine")
2015-11-13 11:09:09 +01:00
def test_one_thousand(self):
self.assertEqual(say(1000), "one thousand")
2015-11-13 11:09:09 +01:00
def test_one_thousand_two_hundred_thirty_four(self):
self.assertEqual(say(1234), "one thousand two hundred thirty-four")
2015-11-13 11:09:09 +01:00
def test_one_million(self):
self.assertEqual(say(1000000), "one million")
2015-11-13 11:09:09 +01:00
def test_one_million_two_thousand_three_hundred_forty_five(self):
2015-11-13 11:09:09 +01:00
self.assertEqual(
say(1002345), "one million two thousand three hundred forty-five"
)
2015-11-13 11:09:09 +01:00
def test_one_billion(self):
self.assertEqual(say(1000000000), "one billion")
2015-11-13 11:09:09 +01:00
def test_a_big_number(self):
self.assertEqual(
say(987654321123),
"nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three",
)
2015-11-13 11:09:09 +01:00
def test_numbers_below_zero_are_out_of_range(self):
with self.assertRaises(ValueError) as err:
say(-1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "input out of range")
def test_numbers_above_999_999_999_999_are_out_of_range(self):
with self.assertRaises(ValueError) as err:
say(1000000000000)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "input out of range")
# Additional tests for this track
def test_one_hundred_seventy(self):
self.assertEqual(say(170), "one hundred seventy")