예제 #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()
예제 #2
0
    def testParseNominal4(self):
        py_calc = pycalc.PyCalc('sin(4+2)')
        result = py_calc.Parse()

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

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

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

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

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

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

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

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