예제 #1
0
    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")
예제 #2
0
 def test_with_and_in_number(self):
     result = text2int('five hundred and two birds')
     self.assertEqual(result, '502 birds')
예제 #3
0
 def test_with_and(self):
     result = text2int('five and two')
     self.assertEqual(result, '5 and 2')
예제 #4
0
 def test_big_number(self):
     result = text2int('fifty six thousand birds')
     self.assertEqual(result, '56000 birds')
예제 #5
0
 def test_simple_number(self):
     result = text2int('what is five plus three')
     self.assertEqual(result, 'what is 5 plus 3')
예제 #6
0
 def test_no_number(self):
     result = text2int('what is up')
     self.assertEqual(result, 'what is up')