Skip to content

Instantly share code, notes, and snippets.

@shostakovich
Created July 2, 2012 16:25
Show Gist options
  • Save shostakovich/3034091 to your computer and use it in GitHub Desktop.
Save shostakovich/3034091 to your computer and use it in GitHub Desktop.
FizzBuzz Kata 4th iteration
class Game
def self.play
(1..100).map { |n| Kid.answer_to(n) }
end
class Kid
def self.answer_to(number)
if (number % 15).zero?
"FizzBuzz"
elsif (number % 3).zero?
"Fizz"
elsif (number % 5).zero?
"Buzz"
else
number
end
end
end
end
describe Game do
it "asks the kids for 100 times" do
Game.play.length.should be == 100
end
end
describe Game::Kid do
it "replies with number for any number" do
Game::Kid.answer_to(1).should be == 1
end
it "replies with 'Fizz' for numbers divisable by 3" do
Game::Kid.answer_to(3).should == "Fizz"
end
it "replies with 'Buzz' for numbers divisable by 5" do
Game::Kid.answer_to(5).should be == "Buzz"
end
it "replies with 'FizzBuzz' for numbers divisable by 3, 5" do
Game::Kid.answer_to(15).should be == "FizzBuzz"
end
end
@shostakovich
Copy link
Author

Obvious stuff of course.. Though is it really obvious? If you start to solve the same problem over and over again you notice that the outcome is slightly different each time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment