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))
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)
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))
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))
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))
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))
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))