Skip to content

Instantly share code, notes, and snippets.

@MicTech
Created December 27, 2017 09:34
Show Gist options
  • Save MicTech/da45c4680bbdaf64796435a1ff7d0193 to your computer and use it in GitHub Desktop.
Save MicTech/da45c4680bbdaf64796435a1ff7d0193 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