shareable: Improve TestExtend

This commit is contained in:
Hajime Hoshi 2018-12-16 05:09:43 +09:00
parent 08a369b8fd
commit 17b225083d

View File

@ -204,10 +204,10 @@ func Disabled_TestReshared(t *testing.T) {
} }
func TestExtend(t *testing.T) { func TestExtend(t *testing.T) {
const w, h = 100, 100 const w0, h0 = 100, 100
img0 := NewImage(w, h) img0 := NewImage(w0, h0)
p0 := make([]byte, 4*w*h) p0 := make([]byte, 4*w0*h0)
for i := 0; i < w*h; i++ { for i := 0; i < w0*h0; i++ {
p0[4*i] = byte(i) p0[4*i] = byte(i)
p0[4*i+1] = byte(i) p0[4*i+1] = byte(i)
p0[4*i+2] = byte(i) p0[4*i+2] = byte(i)
@ -215,18 +215,36 @@ func TestExtend(t *testing.T) {
} }
img0.ReplacePixels(p0) img0.ReplacePixels(p0)
img1 := NewImage(bigSize, bigSize) const w1, h1 = 1025, 100
p1 := make([]byte, 4*bigSize*bigSize) img1 := NewImage(w1, h1)
p1 := make([]byte, 4*w1*h1)
for i := 0; i < w1*h1; i++ {
p1[4*i] = byte(i)
p1[4*i+1] = byte(i)
p1[4*i+2] = byte(i)
p1[4*i+3] = byte(i)
}
// Ensure to allocate // Ensure to allocate
img1.ReplacePixels(p1) img1.ReplacePixels(p1)
for j := 0; j < h; j++ { for j := 0; j < h0; j++ {
for i := 0; i < w; i++ { for i := 0; i < w0; i++ {
got := img0.At(i, j) got := img0.At(i, j)
c := byte(i + w*j) c := byte(i + w0*j)
want := color.RGBA{c, c, c, c} want := color.RGBA{c, c, c, c}
if got != want { if got != want {
t.Errorf("got: %v, want: %v", got, want) t.Errorf("img0.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
for j := 0; j < h1; j++ {
for i := 0; i < w1; i++ {
got := img1.At(i, j)
c := byte(i + w1*j)
want := color.RGBA{c, c, c, c}
if got != want {
t.Errorf("img1.At(%d, %d): got: %v, want: %v", i, j, got, want)
} }
} }
} }