github.com/korsakjakub/snk@v0.0.0-20230625212658-1d6c119c67ee/game_test.go (about) 1 package main 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestMove(t *testing.T) { 9 conf = Config{ 10 Width: 4, 11 Height: 4, 12 } 13 snake := actor{s: shape{{x: 0, y: 0}, {x: 1, y: 0}, {x: 2, y: 0}}, r: '#'} 14 fruit := actor{s: shape{{x: 0, y: 1}}, r: '*'} 15 s := screen{nil, 4, 4} 16 _ = s.drawScreen(snake, fruit) 17 points := 0 18 nextMove := up 19 game := game{snake: snake, fruit: fruit, points: points, screen: s} 20 game = game.move(nextMove) 21 t.Log(game.drawScreen()) 22 game = game.move(nextMove) 23 t.Log(game.drawScreen()) 24 game = game.move(nextMove) 25 t.Log(game.drawScreen()) 26 27 want := [][]rune{{46, 46, 46, 46}, {42, 46, 35, 46}, {46, 46, 35, 46}, {46, 46, 35, 46}} 28 if !reflect.DeepEqual(game.screen.s, want) { 29 t.Errorf("wanted: %v, got: %v", want, game.screen.s) 30 } 31 }