Skip to content

Instantly share code, notes, and snippets.

@kikito
Created December 3, 2011 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikito/1427574 to your computer and use it in GitHub Desktop.
Save kikito/1427574 to your computer and use it in GitHub Desktop.
half-finished life in lua
local AliveCell = {}
function AliveCell:new(neighbors)
return setmetatable({neighbors = neighbors}, {__index = self})
end
function AliveCell:willLive()
return cell.neighbors > 1 and cell.neighbors < 4
end
local DeadCell = {}
function DeadCell:new(neighbors)
return setmetatable({neighbors = neighbors}, {__index = self})
end
function DeadCell:willLive()
return cell.neighbors == 3
end
describe("Cell", function()
describe("willLive", function()
it("returns false when it has 0 neighbors", function()
local cell = AliveCell:new(0)
assert_false(cell:willLive())
end)
it("returns false when it has 1 neighbor", function()
local cell = AliveCell(1)
assert_false(willLive(cell))
end)
describe("with 2 neighbors", function()
it("returns true if is alive", function()
local cell = newAliveCell(2)
assert_true(willLive(cell))
end)
it("returns false if is dead", function()
local cell = newDeadCell(2)
assert_false(willLive(cell))
end)
end)
it("return false with 4 neighbors", function()
local cell = newAliveCell(4)
assert_false(willLive(cell))
end)
end)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment