Filling in a few more tests

This commit is contained in:
Dan Buch 2012-12-08 23:08:40 -05:00
parent f1ab95c68f
commit 8a858a9a11

View File

@ -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()
}
}