-
-
Save rarous/3897226 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 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