Created
November 19, 2015 02:16
-
-
Save joelbyler/278663f1c02427e0a60a to your computer and use it in GitHub Desktop.
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 '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