Skip to content

Instantly share code, notes, and snippets.

@mlangenberg
Created August 21, 2008 09:29
Show Gist options
  • Save mlangenberg/6527 to your computer and use it in GitHub Desktop.
Save mlangenberg/6527 to your computer and use it in GitHub Desktop.
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