Created
December 3, 2011 17:03
-
-
Save kikito/1427574 to your computer and use it in GitHub Desktop.
half-finished life in lua
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
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