Created
August 21, 2008 09:29
-
-
Save mlangenberg/6527 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
require 'rubygems' | |
require 'spec' | |
## implementatie | |
class Calculator | |
attr_reader :result | |
def initialize(a = 0) | |
@result = a | |
end | |
def telop(a, b) | |
a+b | |
end | |
def vermenigvuldig(a,b) | |
a*b | |
end | |
def plus(a) | |
Calculator.new(@result + a) | |
end | |
end | |
## test | |
describe Calculator do | |
it "zou moeten kunnen optellen" do | |
calc = Calculator.new | |
calc.telop(2, 3).should == 5 | |
end | |
it "zou moeten kunnen vermenigvuldigen" do | |
calc = Calculator.new | |
calc.vermenigvuldig(2,3).should == 6 | |
end | |
it do | |
calc = Calculator.new(5) | |
calc.plus(5).plus(3).result.should == 13 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment