Esempio n. 1
0
    def test_result_calc_twice(self):
        dsp.process('1', self.operandstack, self.operatorstack)
        dsp.process('+', self.operandstack, self.operatorstack)
        dsp.process('2', self.operandstack, self.operatorstack)
        dsp.process('*', self.operandstack, self.operatorstack)
        dsp.process('3', self.operandstack, self.operatorstack)

        self.assertEquals(7, dsp.result(self.operandstack, self.operatorstack))
        self.assertEquals([], dsp._dump(self.operandstack))
        self.assertEquals([], dsp._dump(self.operatorstack))
Esempio n. 2
0
def _eval_expr(expr, wcuridx, operandstack, operatorstack):
    while expr_not_end(expr, wcuridx):
        c = next_char(expr, wcuridx)
        if '(' == c:
            dsp.push_operand(_eval_expr(expr, wcuridx, [], []), operandstack)
        elif ')' == c:
            return dsp.result(operandstack, operatorstack)
        else:
            dsp.process(c, operandstack, operatorstack)

    return dsp.result(operandstack, operatorstack)
Esempio n. 3
0
    def test_num_divide_num_plus(self):
        dsp.process('4', self.operandstack, self.operatorstack)
        dsp.process('/', self.operandstack, self.operatorstack)
        dsp.process('2', self.operandstack, self.operatorstack)
        dsp.process('+', self.operandstack, self.operatorstack)

        self.assertEquals([2], dsp._dump(self.operandstack))
        self.assertEquals(['+'], dsp._dump(self.operatorstack))
Esempio n. 4
0
    def test_num_subtract_num_divide(self):
        dsp.process('4', self.operandstack, self.operatorstack)
        dsp.process('-', self.operandstack, self.operatorstack)
        dsp.process('2', self.operandstack, self.operatorstack)
        dsp.process('/', self.operandstack, self.operatorstack)

        self.assertEquals([4, 2], dsp._dump(self.operandstack))
        self.assertEquals(['-', '/'], dsp._dump(self.operatorstack))
Esempio n. 5
0
    def test_num_subtract_num_plus(self):
        dsp.process('3', self.operandstack, self.operatorstack)
        dsp.process('-', self.operandstack, self.operatorstack)
        dsp.process('2', self.operandstack, self.operatorstack)
        dsp.process('+', self.operandstack, self.operatorstack)

        self.assertEquals([1], dsp._dump(self.operandstack))
        self.assertEquals(['+'], dsp._dump(self.operatorstack))
Esempio n. 6
0
    def test_num_multiply_num_plus(self):
        dsp.process('3', self.operandstack, self.operatorstack)
        dsp.process('*', self.operandstack, self.operatorstack)
        dsp.process('2', self.operandstack, self.operatorstack)
        dsp.process('+', self.operandstack, self.operatorstack)

        self.assertEquals([6], dsp._dump(self.operandstack))
        self.assertEquals(['+'], dsp._dump(self.operatorstack))
Esempio n. 7
0
    def test_result_num(self):
        dsp.process('3', self.operandstack, self.operatorstack)

        self.assertEquals(3, dsp.result(self.operandstack, self.operatorstack))
        self.assertEquals([], dsp._dump(self.operandstack))
        self.assertEquals([], dsp._dump(self.operatorstack))