Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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))))
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def test_ones(self):
   self.assertEqual(num2word(5), "five")
Exemplo n.º 9
0
 def test_hundred_tens_and_ones(self):
   self.assertEqual(num2word(824), "eight hundred and twenty-four")
Exemplo n.º 10
0
 def test_tens(self):
   self.assertEqual(num2word(40), "forty")
Exemplo n.º 11
0
 def test_teens(self):
   self.assertEqual(num2word(13), "thirteen")
Exemplo n.º 12
0
 def test_hundred(self):
   self.assertEqual(num2word(200), "two hundred")
Exemplo n.º 13
0
 def test_tens_and_one(self):
   self.assertEqual(num2word(42), "forty-two")
Exemplo n.º 14
0
 def test_zero(self):
   self.assertEqual(num2word(0), "zero")
Exemplo n.º 15
0
 def test_challenge4(self):
     print(num2word(fibR(12)))
Exemplo n.º 16
0
def my_replace(match):
    match = match.group()
    try:
        return ' ' + num2word(round(float(match))) + ' '
    except Exception:
        return ' '
Exemplo n.º 17
0
 def test_hundred_and_tens(self):
   self.assertEqual(num2word(730), "seven hundred and thirty")
Exemplo n.º 18
0
 def test_hundred_and_ones(self):
   self.assertEqual(num2word(605), "six hundred and five")
Exemplo n.º 19
0
 def __init__(self, number):
     self.number = number
     self.name = num2word(number)
     self.visited = False
     self.child = None
Exemplo n.º 20
0
 def test_thousands(self):
   self.assertEqual(num2word(1000), "one thousand")