github.com/korsakjakub/snk@v0.0.0-20230625212658-1d6c119c67ee/screen_test.go (about) 1 package main 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestDrawScreen(t *testing.T) { 9 snake := actor{s: shape{{x: 0, y: 0}, {x: 1, y: 0}, {x: 2, y: 0}}, r: '#'} 10 fruit := actor{s: shape{{x: 0, y: 1}}, r: '*'} 11 s := screen{nil, 3, 3} 12 got := s.drawScreen(snake, fruit) 13 want := [][]rune{{35, 35, 35}, {42, 46, 46}, {46, 46, 46}} 14 15 if !reflect.DeepEqual(got.s, want) { 16 t.Errorf("wanted: %v, got: %v", want, got) 17 } 18 } 19 20 func TestPrintScreen(t *testing.T) { 21 conf = Config{ 22 Width: 3, 23 Height: 3, 24 } 25 snake := actor{s: shape{{x: 0, y: 0}, {x: 1, y: 0}, {x: 2, y: 0}}, r: '#'} 26 fruit := actor{s: shape{{x: 0, y: 1}}, r: '*'} 27 s := screen{nil, 3, 3} 28 _ = s.drawScreen(snake, fruit) 29 got := s.s 30 want := [][]rune{{35, 35, 35}, {42, 46, 46}, {46, 46, 46}} 31 if !reflect.DeepEqual(got, want) { 32 t.Errorf("wanted: %v, got: %v", want, got) 33 } 34 } 35 36 func TestModuloAdd(t *testing.T) { 37 conf = Config{ 38 Width: 3, 39 Height: 3, 40 } 41 s := shape{{x: 1, y: 0}, {x: 2, y: 0}} 42 d := coord{x: 0, y: -1} 43 got := s.moduloAdd(d) 44 want := shape{{1, 0}, {2, 0}, {2, 2}} 45 if !reflect.DeepEqual(got, want) { 46 t.Errorf("wanted: %v, got: %v", want, got) 47 } 48 }