Created
December 3, 2011 15:48
-
-
Save kolman/1427422 to your computer and use it in GitHub Desktop.
Game of Life rules
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
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