Пример #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', '+'])