Created
July 18, 2012 18:39
-
-
Save wnoizumi/3137967 to your computer and use it in GitHub Desktop.
FizzBuzz kata using ruby
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
module FizzBuzz | |
def as_fb | |
return 'FizzBuzz' if self % 15 == 0 | |
return 'Fizz' if self % 3 == 0 | |
return 'Buzz' if self % 5 == 0 | |
return self.to_s | |
end | |
end | |
class Fixnum | |
include FizzBuzz | |
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_relative "fizz_buzz" | |
describe FizzBuzz do | |
it 'Divisivel por tres e por cinco deve retornar FizzBuzz' do | |
15.as_fb.should == 'FizzBuzz' | |
30.as_fb.should == 'FizzBuzz' | |
90.as_fb.should == 'FizzBuzz' | |
end | |
it 'Divisivel apenas por tres deve retornar Fizz' do | |
3.as_fb.should == 'Fizz' | |
9.as_fb.should == 'Fizz' | |
12.as_fb.should == 'Fizz' | |
end | |
it 'Divisivel apenas por cinco deve retornar Buzz' do | |
5.as_fb.should == 'Buzz' | |
10.as_fb.should == 'Buzz' | |
20.as_fb.should == 'Buzz' | |
end | |
it 'Nao divisivel nem por tres e nem por cinco deve retornar o proprio numero' do | |
1.as_fb.should == '1' | |
7.as_fb.should == '7' | |
22.as_fb.should == '22' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment