Skip to content

Instantly share code, notes, and snippets.

@wnoizumi
Created July 18, 2012 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnoizumi/3137967 to your computer and use it in GitHub Desktop.
Save wnoizumi/3137967 to your computer and use it in GitHub Desktop.
FizzBuzz kata using ruby
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
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