From 8a858a9a11516e050f621589db107f6b242aa9e1 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 8 Dec 2012 23:08:40 -0500 Subject: [PATCH] Filling in a few more tests --- conway/go/conway_test.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/conway/go/conway_test.go b/conway/go/conway_test.go index ba275e4..25e3c3a 100644 --- a/conway/go/conway_test.go +++ b/conway/go/conway_test.go @@ -28,6 +28,22 @@ func TestNewGameOfLifeHasCorrectDimensions(t *testing.T) { func TestLiveCellWithFewerThanTwoLiveNeighborsDies(t *testing.T) { state := NewGameState(16, 16) state.ImportState(TEST_SIMPLE_INITIAL_STATE) + + if value, err := state.Get(0, 0); err != nil || value != 1 { + t.Fail() + } + + if value, err := state.Get(1, 0); err != nil || value != 1 { + t.Fail() + } + + if value, err := state.Get(0, 1); err != nil || value != 1 { + t.Fail() + } + + if value, err := state.Get(1, 1); err != nil || value != 1 { + t.Fail() + } } func TestNewGameStatesAreAllDead(t *testing.T) { @@ -41,13 +57,31 @@ func TestNewGameStatesAreAllDead(t *testing.T) { } } +func TestGameStateCanGetCellValueByCoords(t *testing.T) { + state := NewGameState(8, 8) + if value, err := state.Get(2, 2); err != nil || value != 0 { + t.Fail() + } +} + +func TestGameStateCanSetCellValueByCoords(t *testing.T) { + state := NewGameState(8, 8) + if err := state.Set(2, 5, 1); err != nil { + t.Fail() + } + + if value, err := state.Get(2, 5); err != nil || value != 1 { + 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 { + if value, err := state.Get(0, 1); err != nil || value != 1 { t.Fail() } } @@ -59,7 +93,7 @@ func TestGameStateCanDeadenCellsByCoords(t *testing.T) { t.Fail() } - if state.Rows[1].Cols[0] != 1 { + if value, err := state.Get(0, 1); err != nil || value != 1 { t.Fail() } @@ -67,7 +101,7 @@ func TestGameStateCanDeadenCellsByCoords(t *testing.T) { t.Fail() } - if state.Rows[1].Cols[0] != 0 { + if value, err := state.Get(0, 1); err != nil || value != 0 { t.Fail() } }