- 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".
Last active
October 4, 2018 16:18
-
-
Save kevinnio/faeef631f6eb0015f03ac1ebb7604e41 to your computer and use it in GitHub Desktop.
The FizzBuzz kata
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 './fizzbuzz' | |
fizzbuzz = FizzBuzz.new | |
(1..100).each { |number| puts fizzbuzz.print_number(number) } |
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 FizzBuzz | |
def print_number(number) | |
# Write your code here | |
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 './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