2015-11-13 11:09:09 +01:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from say import (
|
|
|
|
|
say,
|
|
|
|
|
)
|
2015-11-13 11:09:09 +01:00
|
|
|
|
2020-10-15 12:46:24 -04:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json`
|
2017-03-29 19:55:40 +02:00
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
|
2015-11-13 11:09:09 +01:00
|
|
|
class SayTest(unittest.TestCase):
|
2017-03-29 19:55:40 +02:00
|
|
|
def test_zero(self):
|
|
|
|
|
self.assertEqual(say(0), "zero")
|
|
|
|
|
|
2015-11-13 11:09:09 +01:00
|
|
|
def test_one(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1), "one")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_fourteen(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(14), "fourteen")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_twenty(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(20), "twenty")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_twenty_two(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(22), "twenty-two")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_hundred(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(100), "one hundred")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_hundred_twenty_three(self):
|
2020-01-12 19:25:56 +02:00
|
|
|
self.assertEqual(say(123), "one hundred twenty-three")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_thousand(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1000), "one thousand")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_thousand_two_hundred_thirty_four(self):
|
2020-01-12 19:25:56 +02:00
|
|
|
self.assertEqual(say(1234), "one thousand two hundred thirty-four")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_million(self):
|
2019-07-05 12:38:00 +03:00
|
|
|
self.assertEqual(say(1000000), "one million")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
def test_one_million_two_thousand_three_hundred_forty_five(self):
|
2015-11-13 11:09:09 +01:00
|
|
|
self.assertEqual(
|
2020-01-12 19:25:56 +02:00
|
|
|
say(1002345), "one million two thousand three hundred forty-five"
|
|
|
|
|
)
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_billion(self):
|
2019-07-05 12:38:00 +03:00
|
|
|
self.assertEqual(say(1000000000), "one billion")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
def test_a_big_number(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(
|
2020-01-12 19:25:56 +02:00
|
|
|
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
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
def test_numbers_below_zero_are_out_of_range(self):
|
2017-12-12 18:11:43 +00:00
|
|
|
with self.assertRaisesWithMessage(ValueError):
|
2020-01-12 19:25:56 +02:00
|
|
|
say(-1)
|
2017-03-29 19:55:40 +02:00
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
def test_numbers_above_999_999_999_999_are_out_of_range(self):
|
2017-12-12 18:11:43 +00:00
|
|
|
with self.assertRaisesWithMessage(ValueError):
|
2020-01-12 19:25:56 +02:00
|
|
|
say(1000000000000)
|
2017-03-29 19:55:40 +02:00
|
|
|
|
2020-09-11 20:48:13 +02:00
|
|
|
# Additional tests for this track
|
|
|
|
|
def test_one_hundred_seventy(self):
|
|
|
|
|
self.assertEqual(say(170), "one hundred seventy")
|
|
|
|
|
|
2017-12-12 18:11:43 +00:00
|
|
|
# Utility functions
|
|
|
|
|
def assertRaisesWithMessage(self, exception):
|
|
|
|
|
return self.assertRaisesRegex(exception, r".+")
|
|
|
|
|
|
2016-11-29 09:44:47 +01:00
|
|
|
|
2020-01-12 19:25:56 +02:00
|
|
|
if __name__ == "__main__":
|
2015-11-13 11:09:09 +01:00
|
|
|
unittest.main()
|