Example #1
0
    def Parse(self):
        """ Parses arguments and parse expression."""
        args = self._parser.parse_args()

        if args.EXPRESSION:
            py_calc = pycalc.PyCalc(args.EXPRESSION)
            print py_calc.Parse()
Example #2
0
    def testParseNominal4(self):
        py_calc = pycalc.PyCalc('sin(4+2)')
        result = py_calc.Parse()

        self.assertEqual(result, -0.27941549819892586)
Example #3
0
    def testParseNominal3(self):
        py_calc = pycalc.PyCalc('(4+2)*(2+4)')
        result = py_calc.Parse()

        self.assertEqual(result, 36)
Example #4
0
    def testParseNominal2(self):
        py_calc = pycalc.PyCalc('4+2')
        result = py_calc.Parse()

        self.assertEqual(result, 6)
Example #5
0
    def testParseNominal(self):
        py_calc = pycalc.PyCalc('(4+2)*4')
        result = py_calc.Parse()

        self.assertEqual(result, 24)
Example #6
0
    def testToPostfixSin(self):
        py_calc = pycalc.PyCalc('')
        result = py_calc._ToPostfix('sin(2+3)')

        self.assertEqual(result, ['2', '3', '+', 'sin'])
Example #7
0
    def testToPostfixFail(self):
        py_calc = pycalc.PyCalc('')
        result = py_calc._ToPostfix('test')

        self.assertEqual(result, [])
Example #8
0
    def testToPostfixNominal(self):
        py_calc = pycalc.PyCalc('')
        result = py_calc._ToPostfix('(4+2)*4')

        self.assertEqual(result, ['4', '2', '+', '4', '*'])
Example #9
0
    def testToPostfixSimply(self):
        py_calc = pycalc.PyCalc('')
        result = py_calc._ToPostfix('3+4')

        self.assertEqual(result, ['3', '4', '+'])