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

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

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

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

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

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

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

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

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