Skip to content

Instantly share code, notes, and snippets.

@kevinnio
Last active October 4, 2018 16:18
Show Gist options
  • Save kevinnio/faeef631f6eb0015f03ac1ebb7604e41 to your computer and use it in GitHub Desktop.
Save kevinnio/faeef631f6eb0015f03ac1ebb7604e41 to your computer and use it in GitHub Desktop.
The FizzBuzz kata

The FizzBuzz Kata

- Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz"
  instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both
  three and five print "FizzBuzz".
require './fizzbuzz'
fizzbuzz = FizzBuzz.new
(1..100).each { |number| puts fizzbuzz.print_number(number) }
class FizzBuzz
def print_number(number)
# Write your code here
end
end
require './fizzbuzz'
RSpec.describe FizzBuzz do
subject { described_class.new }
describe '#print_number' do
context 'when the number is multiple of 3' do
it 'returns "FIZZ"' do
[3, 6, 9, 12, 18].each do |number|
expect(subject.print_number(number)).to eq 'FIZZ'
end
end
end
context 'when the number is multiple of 5' do
it 'returns "BUZZ"' do
[5, 10, 20, 25].each do |number|
expect(subject.print_number(number)).to eq 'BUZZ'
end
end
end
context 'when the number is multiple of both 3 and 5' do
it 'returns "FIZZBUZZ"' do
[15, 30, 45, 60].each do |number|
expect(subject.print_number(number)).to eq 'FIZZBUZZ'
end
end
end
context 'when the number is not multiple of 3 or 5' do
it 'returns the same number' do
[1, 2, 4, 7, 11].each do |number|
expect(subject.print_number(number)).to eq number
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment