Created
November 14, 2015 15:59
-
-
Save rgo/c6bbcdbfd33ef62f0468 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
apuntes de + ideas: