Skip to content

Instantly share code, notes, and snippets.

@joelbyler
Created November 19, 2015 02:16
Show Gist options
  • Save joelbyler/278663f1c02427e0a60a to your computer and use it in GitHub Desktop.
Save joelbyler/278663f1c02427e0a60a to your computer and use it in GitHub Desktop.
require 'rspec'
class GameOfLife
def self.will_live?(alive_or_dead, neighbors)
if alive_or_dead == :alive
return true if neighbors == 2 || neighbors == 3
else
return true if neighbors == 3
end
false
end
end
describe GameOfLife do
it 'let a cell die if it has fewer than 2 neighbors' do
expect(GameOfLife.will_live?(:alive, 1)).to eq(false)
end
it 'remains alive with 2 neighbors' do
expect(GameOfLife.will_live?(:alive, 2)).to eq(true)
end
it 'remains alive with 3 neighbors' do
expect(GameOfLife.will_live?(:alive, 3)).to eq(true)
end
it 'remains alive with 4 neighbors' do
expect(GameOfLife.will_live?(:alive, 4)).to eq(false)
end
it 'let a cell die if it has fewer than 2 neighbors' do
expect(GameOfLife.will_live?(:dead, 1)).to eq(false)
end
it 'remains alive with 2 neighbors' do
expect(GameOfLife.will_live?(:dead, 2)).to eq(false)
end
it 'becomes alive with 3 neighbors' do
expect(GameOfLife.will_live?(:dead, 3)).to eq(true)
end
it 'remains alive with 4 neighbors' do
expect(GameOfLife.will_live?(:dead, 2)).to eq(false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment