|
| 1 | +import unittest |
| 2 | + |
| 3 | +from say import say |
| 4 | + |
| 5 | + |
| 6 | +class SayTest(unittest.TestCase): |
| 7 | + |
| 8 | + def test_one(self): |
| 9 | + self.assertEqual("one", say(1)) |
| 10 | + |
| 11 | + def test_fourteen(self): |
| 12 | + self.assertEqual("fourteen", say(14)) |
| 13 | + |
| 14 | + def test_twenty(self): |
| 15 | + self.assertEqual("twenty", say(20)) |
| 16 | + |
| 17 | + def test_twenty_two(self): |
| 18 | + self.assertEqual("twenty-two", say(22)) |
| 19 | + |
| 20 | + def test_one_hundred(self): |
| 21 | + self.assertEqual("one hundred", say(100)) |
| 22 | + |
| 23 | + def test_one_hundred_twenty(self): |
| 24 | + self.assertEqual("one hundred and twenty", say(120)) |
| 25 | + |
| 26 | + def test_one_hundred_twenty_three(self): |
| 27 | + self.assertEqual("one hundred and twenty-three", say(123)) |
| 28 | + |
| 29 | + def test_one_thousand(self): |
| 30 | + self.assertEqual("one thousand", say(1000)) |
| 31 | + |
| 32 | + def test_one_thousand_two_hundred_thirty_four(self): |
| 33 | + self.assertEqual("one thousand two hundred and thirty-four", |
| 34 | + say(1234)) |
| 35 | + |
| 36 | + def test_one_million(self): |
| 37 | + self.assertEqual("one million", say(1e6)) |
| 38 | + |
| 39 | + def test_one_million_two(self): |
| 40 | + self.assertEqual("one million and two", say(1000002)) |
| 41 | + |
| 42 | + def test_1002345(self): |
| 43 | + self.assertEqual( |
| 44 | + "one million two thousand three hundred and forty-five", |
| 45 | + say(1002345)) |
| 46 | + |
| 47 | + def test_one_billion(self): |
| 48 | + self.assertEqual("one billion", say(1e9)) |
| 49 | + |
| 50 | + def test_number_to_large(self): |
| 51 | + with self.assertRaises(AttributeError): |
| 52 | + say(1e12) |
| 53 | + |
| 54 | + def test_number_negative(self): |
| 55 | + with self.assertRaises(AttributeError): |
| 56 | + say(-42) |
| 57 | + |
| 58 | + def test_zero(self): |
| 59 | + self.assertEqual("zero", say(0)) |
| 60 | + |
| 61 | + def test_987654321123(self): |
| 62 | + self.assertEqual("nine hundred and eighty-seven billion " + |
| 63 | + "six hundred and fifty-four million " + |
| 64 | + "three hundred and twenty-one thousand " + |
| 65 | + "one hundred and twenty-three", |
| 66 | + say(987654321123)) |
| 67 | + |
| 68 | +if __name__ == '__main__': |
| 69 | + unittest.main() |
0 commit comments