Skip to content

Instantly share code, notes, and snippets.

@Jimgerneer
Created December 3, 2013 04:17
Show Gist options
  • Save Jimgerneer/7763803 to your computer and use it in GitHub Desktop.
Save Jimgerneer/7763803 to your computer and use it in GitHub Desktop.
FizzBuzz
class FizzBuzz
def self.play(array)
array.collect do | num |
self.fizzbuzz(num) || self.buzz(num) || self.fizz(num) || num
end
end
def self.fizz(n)
'fizz' if n % 3 == 0
end
def self.buzz(n)
'buzz' if n % 5 == 0
end
def self.fizzbuzz(n)
'fizzbuzz' if n % 5 == 0 && n % 3 == 0
end
end
require 'minitest/autorun'
require 'minitest/pride'
require './buzz'
describe FizzBuzz do
describe '#play' do
it 'should take an array and return FizzBuzz' do
result = FizzBuzz.play([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
result.must_equal [1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz', 11, 'fizz', 13, 14, 'fizzbuzz']
end
end
describe '#fizz' do
it 'returns fizz when divisable by 3' do
result = FizzBuzz.fizz(3)
result.must_equal 'fizz'
end
it 'returns fizz when divisable by 3' do
result = FizzBuzz.fizz(2)
result.must_equal nil
end
end
describe '#buzz' do
it 'returns buzz when divisable by 5' do
result = FizzBuzz.buzz(5)
result.must_equal 'buzz'
end
it 'does not return buzz when it is not divisible by 5' do
result = FizzBuzz.buzz(7)
result.must_equal nil
end
end
describe '#fizzbuzz' do
it 'returns fizzbuzz when it is divisable by 5 and divisible by 3' do
result = FizzBuzz.fizzbuzz(15)
result.must_equal 'fizzbuzz'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment