2015-11-13 11:09:09 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from say import say
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SayTest(unittest.TestCase):
|
|
|
|
|
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(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(120), "one hundred and twenty")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_hundred_twenty_three(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(123), "one hundred and 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):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1234), "one thousand two hundred and thirty-four")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
2017-03-11 14:24:03 -05:00
|
|
|
def test_eight_hundred_and_ten_thousand(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(810000), "eight hundred and ten thousand")
|
2017-03-11 14:24:03 -05:00
|
|
|
|
2015-11-13 11:09:09 +01:00
|
|
|
def test_one_million(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1e6), "one million")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_million_two(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1000002), "one million and two")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_1002345(self):
|
|
|
|
|
self.assertEqual(
|
2017-03-23 13:37:20 +01:00
|
|
|
say(1002345),
|
|
|
|
|
"one million two thousand three hundred and forty-five")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_one_billion(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(1e9), "one billion")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_number_to_large(self):
|
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
|
say(1e12)
|
|
|
|
|
|
|
|
|
|
def test_number_negative(self):
|
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
|
say(-42)
|
|
|
|
|
|
|
|
|
|
def test_zero(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(say(0), "zero")
|
2015-11-13 11:09:09 +01:00
|
|
|
|
|
|
|
|
def test_987654321123(self):
|
2017-03-23 13:37:20 +01:00
|
|
|
self.assertEqual(
|
|
|
|
|
say(987654321123), ("nine hundred and eighty-seven billion "
|
|
|
|
|
"six hundred and fifty-four million "
|
|
|
|
|
"three hundred and twenty-one thousand "
|
|
|
|
|
"one hundred and twenty-three"))
|
2015-11-13 11:09:09 +01:00
|
|
|
|
2016-11-29 09:44:47 +01:00
|
|
|
|
2015-11-13 11:09:09 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|