def test_zero_to_nineteen(self): expected_word = "zero" got_word = num2word(0) self.assertEqual(expected_word, got_word) expected_word = "eight" got_word = num2word(8) self.assertEqual(expected_word, got_word)
def test_two_digit(self): expected_word = "thirty four" got_word = num2word(34) self.assertEqual(expected_word, got_word) expected_word = "seventy" got_word = num2word(70) self.assertEqual(expected_word, got_word)
def test_six_digit(self): expected_word = "three hundred and forty nine thousand and sixty two" got_word = num2word(349062) self.assertEqual(expected_word, got_word) expected_word = "eight hundred thousand" got_word = num2word(800000) self.assertEqual(expected_word, got_word)
def test_four_digit(self): expected_word = "two thousand four hundred and sixty nine" got_word = num2word(2469) self.assertEqual(expected_word, got_word) expected_word = "four thousand" got_word = num2word(4000) self.assertEqual(expected_word, got_word) expected_word = "six thousand and one hundred" got_word = num2word(6100) self.assertEqual(expected_word, got_word)
def test_three_digit(self): expected_word = "seven hundred and eighty one" got_word = num2word(781) self.assertEqual(expected_word, got_word) expected_word = "one hundred" got_word = num2word(100) self.assertEqual(expected_word, got_word) expected_word = "two hundred and fifty" got_word = num2word(250) self.assertEqual(expected_word, got_word) expected_word = "three hundred and one" got_word = num2word(301) self.assertEqual(expected_word, got_word)
def normalize_number(self, number): """Normalize the numbers before the decimal points into english words using num2words module. Whitespaces and non-digit char such as ',' are ignored :param number: input number, string type :return: normalized english words, string type """ return ' '.join(num2word(''.join(re.findall(r'\d', number))))
def test_five_digit(self): expected_word = "twenty two thousand four hundred and sixty nine" got_word = num2word(22469) self.assertEqual(expected_word, got_word) expected_word = "thirty thousand" got_word = num2word(30000) self.assertEqual(expected_word, got_word) expected_word = "thirty thousand and two" got_word = num2word(30002) self.assertEqual(expected_word, got_word) expected_word = "twelve thousand and fifteen" got_word = num2word(12015) self.assertEqual(expected_word, got_word) expected_word = "sixty thousand and four hundred" got_word = num2word(60400) self.assertEqual(expected_word, got_word)
def test_ones(self): self.assertEqual(num2word(5), "five")
def test_hundred_tens_and_ones(self): self.assertEqual(num2word(824), "eight hundred and twenty-four")
def test_tens(self): self.assertEqual(num2word(40), "forty")
def test_teens(self): self.assertEqual(num2word(13), "thirteen")
def test_hundred(self): self.assertEqual(num2word(200), "two hundred")
def test_tens_and_one(self): self.assertEqual(num2word(42), "forty-two")
def test_zero(self): self.assertEqual(num2word(0), "zero")
def test_challenge4(self): print(num2word(fibR(12)))
def my_replace(match): match = match.group() try: return ' ' + num2word(round(float(match))) + ' ' except Exception: return ' '
def test_hundred_and_tens(self): self.assertEqual(num2word(730), "seven hundred and thirty")
def test_hundred_and_ones(self): self.assertEqual(num2word(605), "six hundred and five")
def __init__(self, number): self.number = number self.name = num2word(number) self.visited = False self.child = None
def test_thousands(self): self.assertEqual(num2word(1000), "one thousand")