From 3ca340d80ae8a4e55e069482c766adb38caff51f Mon Sep 17 00:00:00 2001 From: Chad Clark Date: Fri, 1 Mar 2024 04:55:21 +0000 Subject: [PATCH] tests --- src/engine/engine_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go index 81a9d2b..3f16f25 100644 --- a/src/engine/engine_test.go +++ b/src/engine/engine_test.go @@ -148,6 +148,32 @@ func TestCompleteRow(t *testing.T) { } } +func TestGameOver(t *testing.T) { + gameRoot, gameInput, gameOutput := NewGame() + + gameInput <- PlayInputPause + game := <-gameOutput + + if game.State != StateRunning { + t.Errorf("Game not running. %d", game.State) + } + + for i := 1; i < 18; i++ { + gameRoot.Field[i][5] = 1 + gameRoot.Field[i][6] = 1 + } + + gameInput <- PlayInputPause + game = <-gameOutput + + gameInput <- PlayInputDrop + game = <-gameOutput + + if game.State != StateGameOver { + t.Errorf("Game not over. %d", game.State) + } +} + // func TestGetDebugState(t *testing.T) { // // FIXME // } @@ -265,6 +291,8 @@ func TestPauseGame(t *testing.T) { gameInput <- PlayInputPause time.Sleep(3 * time.Second) + gameInput <- PlayInputDrop + gameInput <- PlayInputPause game = <-gameOutput log.Printf("%+v", game)