alexch/learn_ruby

Problem with Exercise 12 RPNCalculator test

tmconrad001 opened this issue · 0 comments

"resolves operator precedence unambiguously" test tries doing two consecutive calculations without resetting the calculator. Basically, it is testing whether:
2+3_((1 + 2) * 3)==1+(2_3)

A fix would to be to require a method that resets the calculator and use that between the tests, or create a new instance of RPNCalculator before the test.

Relevant Code in rpn_calculator_spec.rb:

it "resolves operator precedence unambiguously" do
    #1 2 + 3 * => (1 + 2) * 3
    calculator.push(1)
    calculator.push(2)
    calculator.plus
    calculator.push(3)
    calculator.times
    calculator.value.should == (1+2)*3

    ####
    #Tom Conrad: Error here.  Calculator has
    #to be reset.
    ####

    #1 2 3 * + => 1 + (2 * 3)
    calculator.push(1)
    calculator.push(2)
    calculator.push(3)
    calculator.times
    calculator.plus
    calculator.value.should == 1+(2*3)
  end