Skip to content

Instantly share code, notes, and snippets.

@rgo
Created November 14, 2015 15:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgo/c6bbcdbfd33ef62f0468 to your computer and use it in GitHub Desktop.
Save rgo/c6bbcdbfd33ef62f0468 to your computer and use it in GitHub Desktop.
describe 'Game of life w/o primitives and one dot per line' do
let(:live_cell) { LiveCell.new }
let(:dead_cell) { DeadCell.new }
context 'live cell' do
it 'dies with less than 2 neighbours' do
alive_cells = Neighbours.new(LiveCell.new)
expect(live_cell.next(alive_cells)).to be_a_kind_of DeadCell
end
it 'lives with 2 neighbours' do
alive_cells = Neighbours.new(LiveCell.new, LiveCell.new)
expect(live_cell.next(alive_cells)).to be_a_kind_of LiveCell
end
# it 'dies with more than 3 neighbours' do
# expect(live_cell.next(5)).to be_a_kind_of DeadCell
# end
end
# context 'dead cell' do
# it 'lives with 3 neighbours' do
# expect(dead_cell.next(3)).to be_a_kind_of LiveCell
# end
# end
end
class Neighbours
def initialize(*neighbours)
@neighbours = neighbours
end
end
class LiveCell
def next(neighbours)
if neighbours.size == 2 || neighbours.size == 3
LiveCell.new
else
DeadCell.new
end
end
end
class DeadCell
def next(neighbours)
if neighbours.size == 3
LiveCell.new
else
DeadCell.new
end
end
end
@jrub
Copy link

jrub commented Nov 14, 2015

apuntes de + ideas:

  • hashmap de 'rules' (clave de colección y key del resultado)
  • excepciones como ceros/null/muerte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment