-
-
Save Stormwind/cfbba9f7f3ed0bbfa8ab 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 | |
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 |
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 '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