image: Add test

This commit is contained in:
Hajime Hoshi 2015-01-22 11:27:50 +09:00
parent afe4c76b50
commit 2ab7c2eb9b
2 changed files with 18 additions and 2 deletions

View File

@ -171,6 +171,7 @@ func (i *Image) At(x, y int) color.Color {
//
// This function may be slow (as for implementation, this calls glTexSubImage2D).
func (i *Image) ReplacePixels(p []uint8) error {
// TODO: Can we set p to pixels?
i.pixels = nil
w, h := i.Size()
l := 4 * w * h

View File

@ -203,8 +203,23 @@ func TestReplacePixels(t *testing.T) {
img0.ReplacePixels(img.Pix)
for j := 0; j < img0.Bounds().Size().Y; j++ {
for i := 0; i < img0.Bounds().Size().X; i++ {
got := img.At(i, j)
want := img0.At(i, j)
got := img0.At(i, j)
want := img.At(i, j)
if got != want {
t.Errorf("img0 At(%d, %d): got %#v; want %#v", i, j, got, want)
}
}
}
p := make([]uint8, 4*size.X*size.Y)
for i, _ := range p {
p[i] = 0x80
}
img0.ReplacePixels(p)
for j := 0; j < img0.Bounds().Size().Y; j++ {
for i := 0; i < img0.Bounds().Size().X; i++ {
got := img0.At(i, j)
want := color.RGBA{p[4*i], p[4*i+1], p[4*i+2], p[4*i+3]}
if got != want {
t.Errorf("img0 At(%d, %d): got %#v; want %#v", i, j, got, want)
}