// TestSpinning2x2 loads an animated GIF and checks that it loops forever and
// the frames have the expected colors.
TestSpinning2x2 loads an animated GIF and checks that it loops forever and
the frames have the expected colors.
// TestSpinning2x2 loads an animated GIF and checks that it loops forever and // the frames have the expected colors .
func TestSpinning2x2(t *testing.T) {
	f, err := os.Open(getResource("spinning-2x2.gif"))
	if err != nil {
		panic(err)
	}
	defer f.Close()
	gifHelper, err := HelperFromReader(f)
	if err != nil {
		t.Fatalf(`err = %v, want nil`, err)
	}
	if _, ok := gifHelper.loopCount.(infiniteLoop); !ok {
		t.Errorf(`loopCount is %T, want infiniteLoop`, gifHelper.loopCount)
	}
	if l := len(gifHelper.Frames); l != 4 {
		t.Fatalf(`%d frames, want 4`, l)
	}
	bounds := gifHelper.Bounds()
	if want := (image.Point{0, 0}); bounds.Min != want {
		t.Fatalf(`Bounds().Min = %v, want %v`, bounds.Min, want)
	}
	if want := (image.Point{2, 2}); bounds.Max != want {
		t.Fatalf(`Bounds().Max = %v, want %v`, bounds.Max, want)
	}
	wantDelays := []time.Duration{
		500 * time.Millisecond,
		100 * time.Millisecond,
		100 * time.Millisecond,
		100 * time.Millisecond,
	}
	backgroundWantColors := [][]color.Color{
		{color.White, color.White},
		{color.Black, color.White},
	}
	frame1WantColors := [][]color.Color{
		{color.Black, color.White},
		{color.White, color.White},
	}
	frame2WantColors := [][]color.Color{
		{color.White, color.Black},
		{color.White, color.White},
	}
	frame3WantColors := [][]color.Color{
		{color.White, color.White},
		{color.White, color.Black},
	}
	wantColors := [][][]color.Color{
		backgroundWantColors,
		frame1WantColors,
		frame2WantColors,
		frame3WantColors,
	}
	for i := 0; i < 4; i++ {
		if actual, want := gifHelper.Delay(), wantDelays[i]; actual != want {
			t.Errorf(`Frame %d; delay = %v, want %v`, i, actual, want)
		}
		wantImage := wantColors[i]
		for y, row := range wantImage {
			for x, c := range row {
				r, g, b, a := gifHelper.At(x, y).RGBA()
				wr, wg, wb, wa := c.RGBA()
				if r != wr || g != wg || b != wb || a != wa {
					t.Errorf(
						`Frame %d @ pixel %d, %d: RGBA channels = %v %v %v %v, want %v %v %v %v`,
						i, x, y,
						r, g, b, a,
						wr, wg, wb, wa,
					)
				}
			}
		}
		if err := gifHelper.NextFrame(); err != nil {
			t.Fatalf(`Frame %d: should be infinite loop, NextFrame = %v`, i, err)
		}
	}
}
func TestSpinning2x2 ( t * testing . T ) { f , err := os . Open ( getResource ( " " ) ) if err != nil { panic ( err ) } defer f . Close ( ) gifHelper , err := HelperFromReader ( f ) if err != nil { t . Fatalf ( `err = %v, want nil` , err ) } if _ , ok := gifHelper . loopCount . ( infiniteLoop ) ; ! ok { t . Errorf ( `loopCount is %T, want infiniteLoop` , gifHelper . loopCount ) } if l := len ( gifHelper . Frames ) ; l != 4 { t . Fatalf ( `%d frames, want 4` , l ) } bounds := gifHelper . Bounds ( ) if want := ( image . Point { 0 , 0 } ) ; bounds . Min != want { t . Fatalf ( `Bounds().Min = %v, want %v` , bounds . Min , want ) } if want := ( image . Point { 2 , 2 } ) ; bounds . Max != want { t . Fatalf ( `Bounds().Max = %v, want %v` , bounds . Max , want ) } wantDelays := [ ] time . Duration { 500 * time . Millisecond , 100 * time . Millisecond , 100 * time . Millisecond , 100 * time . Millisecond , } backgroundWantColors := [ ] [ ] color . Color { { color . White , color . White } , { color . Black , color . White } , } frame1WantColors := [ ] [ ] color . Color { { color . Black , color . White } , { color . White , color . White } , } frame2WantColors := [ ] [ ] color . Color { { color . White , color . Black } , { color . White , color . White } , } frame3WantColors := [ ] [ ] color . Color { { color . White , color . White } , { color . White , color . Black } , } wantColors := [ ] [ ] [ ] color . Color { backgroundWantColors , frame1WantColors , frame2WantColors , frame3WantColors , } for i := 0 ; i < 4 ; i ++ { if actual , want := gifHelper . Delay ( ) , wantDelays [ i ] ; actual != want { t . Errorf ( `Frame %d; delay = %v, want %v` , i , actual , want ) } wantImage := wantColors [ i ] for y , row := range wantImage { for x , c := range row { r , g , b , a := gifHelper . At ( x , y ) . RGBA ( ) wr , wg , wb , wa := c . RGBA ( ) if r != wr || g != wg || b != wb || a != wa { t . Errorf ( `Frame %d @ pixel %d, %d: RGBA channels = %v %v %v %v, want %v %v %v %v` , i , x , y , r , g , b , a , wr , wg , wb , wa , ) } } } if err := gifHelper . NextFrame ( ) ; err != nil { t . Fatalf ( `Frame %d: should be infinite loop, NextFrame = %v` , i , err ) } } }
TestSpinning2x2 loads an animated GIF and checks that it loops forever and
the frames have the expected colors.
TestSpinning2x2 loads an animated GIF and checks that it loops forever and the frames have the expected colors .