Skip to content

Instantly share code, notes, and snippets.

@Em01
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save Em01/47e2a18eb427548bc6ab to your computer and use it in GitHub Desktop.

Select an option

Save Em01/47e2a18eb427548bc6ab to your computer and use it in GitHub Desktop.
CracklePop

Kata written in ruby with full tdd throughout using Rspec

  • irb
  • require './lib/CracklePop'
  • 1.upto(100){|number| puts CracklePop(number) }
def can_be_divided_by_three?(number)
can_be_divided_by?(number, 3)
end
def can_be_divided_by_five?(number)
can_be_divided_by?(number, 5)
end
def can_be_divided_by_fifteen?(number)
can_be_divided_by?(number, 15)
end
def can_be_divided_by?(number, divisor)
number % divisor == 0
end
def CracklePop(number)
return 'CracklePop' if can_be_divided_by_fifteen?(number)
return 'Pop' if can_be_divided_by_five?(number)
return 'Crackle' if can_be_divided_by_three?(number)
number
end
require 'CracklePop'
describe 'CracklePop' do
context 'it knows that a number can be divided by' do
it '3' do
expect(can_be_divided_by_three?(3)).to be_truthy
end
it '5' do
expect(can_be_divided_by_five?(5)).to be_truthy
end
it '15' do
expect(can_be_divided_by_fifteen?(15)).to be_truthy
end
end
context 'it knows that a number cannot be divided by' do
it '3' do
expect(can_be_divided_by_three?(1)).to be_falsey
end
it '5' do
expect(can_be_divided_by_five?(1)).to be_falsey
end
it '15' do
expect(can_be_divided_by_fifteen?(1)).to be_falsey
end
end
context 'when playing the game I am returned' do
it 'the number' do
expect(CracklePop(1)).to eq 1
end
it 'Crackle' do
expect(CracklePop(3)).to eq 'Crackle'
end
it 'Pop' do
expect(CracklePop(5)).to eq 'Pop'
end
it 'CracklePop' do
expect(CracklePop(15)).to eq 'CracklePop'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment