package conway_test import ( "testing" ) import ( . "github.com/meatballhat/box-o-sand/conway/go" ) var TEST_SIMPLE_INITIAL_STATE = NewGameState(16, 16) func init() { tsis := TEST_SIMPLE_INITIAL_STATE tsis.Set(0, 0, 1) tsis.Set(1, 0, 1) tsis.Set(0, 1, 1) tsis.Set(1, 1, 1) } func TestNewGameOfLifeHasCorrectDimensions(t *testing.T) { game := NewGameOfLife(16, 16) if game.Height != 16 || game.Width != 16 { t.Fail() } } func TestLiveCellWithFewerThanTwoLiveNeighborsDies(t *testing.T) { state := NewGameState(16, 16) state.ImportState(TEST_SIMPLE_INITIAL_STATE) } func TestNewGameStatesAreAllDead(t *testing.T) { state := NewGameState(4, 4) for x := 0; x < 3; x++ { for y := 0; y < 3; y++ { if state.Rows[y].Cols[x] != 0 { t.Fail() } } } } func TestGameStateCanEnlivenCellsByCoords(t *testing.T) { state := NewGameState(8, 8) if err := state.Enliven(0, 1); err != nil { t.Fail() } if state.Rows[1].Cols[0] != 1 { t.Fail() } } func TestGameStateCanDeadenCellsByCoords(t *testing.T) { state := NewGameState(8, 8) if err := state.Enliven(0, 1); err != nil { t.Fail() } if state.Rows[1].Cols[0] != 1 { t.Fail() } if err := state.Deaden(0, 1); err != nil { t.Fail() } if state.Rows[1].Cols[0] != 0 { t.Fail() } }