Skip to content

Instantly share code, notes, and snippets.

@Dangeranger
Created November 15, 2014 20:33
Show Gist options
  • Save Dangeranger/d98a0458a4455c2e4e63 to your computer and use it in GitHub Desktop.
Save Dangeranger/d98a0458a4455c2e4e63 to your computer and use it in GitHub Desktop.
require 'set'
class Life
attr_accessor :state
def initialize(previous_state)
@state = advance(previous_state)
end
def advance(previous_state)
next_state = Set.new
previous_state.each do |cell|
num_neighbors(cell)
end
end
def num_neighbors(cell)
end
end
describe "life" do
context "with an empty state" do
let(:life) { Life.new(Set.new) }
it "is not nil" do
expect(life).to_not be_nil
end
it "has a state" do
expect(life.state).to eql(Set.new)
end
end
context "with a single live cell" do
let(:grid) { Set.new.add([0,0]) }
let(:life) { Life.new(grid) }
it "dies on the next cycle" do
expect(life.advance(grid)).to eql(Set.new)
end
end
context "with a 4x4 grid and 4 live cells" do
let(:grid) { Set.new.add([0,0]).add([0,1]).add([1,0]).add([1,1]) }
let(:next_grid) { Set.new.add([0,0]).add([0,1]).add([1,0]).add([1,1]) }
let(:life) { Life.new(grid) }
it "to live forever" do
expect(life.advance(grid)).to eql(next_grid)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment