-
-
Save anonymous/479611af464177edf31b730cc38cd8ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculator | |
attr_reader :mode, :last | |
def initialize(mode=:real) | |
@mode = mode | |
@last = 0 # XXX why this? without @last == nil | |
end | |
def mode=(mode) | |
@mode = mode | |
@last = 0 | |
end | |
def add(a, b) | |
@last = a + b | |
end | |
end | |
class CalculatorTest < MiniTest::Test | |
def test_store_last_result | |
calc = Calculator.new | |
assert_equal 0, calc.last | |
calc.add 1,2 | |
assert_equal 3, calc.last | |
end | |
end | |
=begin | |
1) Failure: | |
CalculatorTest#test_store_last_result [calc.rb:22]: | |
Expected: 0 | |
Actual: nil | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment