def calculate(self, text): """Calculate the output after parsing input. Parameters ---------- text : str A string value which should be parsed Returns ------- int or float: The final result Raises ------ ValueError If the text cannot be succesfully parsed and evaluated to get a result. """ res = self._parser.parse(text2int(text)) if len(res) == 1: return res[0] else: raise ValueError("Unable to Parse")
def test_with_and_in_number(self): result = text2int('five hundred and two birds') self.assertEqual(result, '502 birds')
def test_with_and(self): result = text2int('five and two') self.assertEqual(result, '5 and 2')
def test_big_number(self): result = text2int('fifty six thousand birds') self.assertEqual(result, '56000 birds')
def test_simple_number(self): result = text2int('what is five plus three') self.assertEqual(result, 'what is 5 plus 3')
def test_no_number(self): result = text2int('what is up') self.assertEqual(result, 'what is up')