Skip to content

Instantly share code, notes, and snippets.

@rarous

rarous/gist:3897226

Forked from kolman/gist:1427422
Created Oct 16, 2012
Embed
What would you like to do?
Game of Life rules
module CodeRetreat
open Xunit
type Cell =
| DeadCell of int
| LiveCell of int
let hasChanceToLife (cell:Cell) =
match cell with
| LiveCell(2) | LiveCell(3) -> true
| DeadCell(3) -> true
| _ -> false
[<Fact>]
let ``Cell with less than two neighbors should die``()=
Assert.False (hasChanceToLife (LiveCell(0)))
[<Fact>]
let ``Cell with more than three neighbors should die``()=
Assert.False (hasChanceToLife (LiveCell(4)))
[<Fact>]
let ``Cell with two neighbors should survive``()=
Assert.True (hasChanceToLife (LiveCell(2)))
[<Fact>]
let ``Cell with three neighbors should survive``()=
Assert.True (hasChanceToLife (LiveCell(3)))
[<Fact>]
let ``Dead cell with exactly three neighbors should become alive``()=
Assert.True (hasChanceToLife (DeadCell(3)))
[<Fact>]
let ``Dead cell with two neighbors should not become alive``()=
Assert.False (hasChanceToLife (DeadCell(2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment