Skip to content

Instantly share code, notes, and snippets.

@Stormwind
Created January 29, 2013 06:38
Show Gist options
  • Save Stormwind/cfbba9f7f3ed0bbfa8ab to your computer and use it in GitHub Desktop.
Save Stormwind/cfbba9f7f3ed0bbfa8ab to your computer and use it in GitHub Desktop.
class Calculator
def multiply(first, second)
first * second
end
def two_raised_by(exponent)
if exponent == 0
return 0
end
result = 1
(1 .. exponent).each do
result = multiply(2, result)
end
result
end
end
require 'spec_helper'
describe Calculator do
let(:subject) {Calculator.new}
describe '#multiply' do
it 'returns 4 if you multiply 2 and 2' do
subject.multiply(2, 2).should eq(4)
end
it 'returns 9 if you multiply 3 and 3' do
subject.multiply(3, 3).should eq(9)
end
end
describe '#two_raised_by' do
it 'returns 0 if your exponent is 0' do
subject.two_raised_by(0).should eq(0)
end
it 'returns 8 if your exponent is 3' do
subject.two_raised_by(3).should eq(8)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment