Skip to content

Instantly share code, notes, and snippets.

@kolman
Created December 3, 2011 15:48
Show Gist options
  • Save kolman/1427422 to your computer and use it in GitHub Desktop.
Save kolman/1427422 to your computer and use it in GitHub Desktop.
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 neighbours should die``()=
Assert.False (hasChanceToLife (LiveCell(0)))
[<Fact>]
let ``Cell with more than three neighbours should die``()=
Assert.False (hasChanceToLife (LiveCell(4)))
[<Fact>]
let ``Cell with two neighbours should survive``()=
Assert.True (hasChanceToLife (LiveCell(2)))
[<Fact>]
let ``Cell with three neighbours should survive``()=
Assert.True (hasChanceToLife (LiveCell(3)))
[<Fact>]
let ``Dead cell with exactly three neighbours becomes alive``()=
Assert.True (hasChanceToLife (DeadCell(3)))
[<Fact>]
let ``Dead cell with two neighbours becomes alive``()=
Assert.False (hasChanceToLife (DeadCell(2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment