diff options
author | Ian Davis <nospam@iandavis.com> | 2018-09-25 15:33:49 +0100 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-09-25 16:07:59 +0000 |
commit | 36a3d4f3fea7bbb22be061fbe830420990cd3ecf (patch) | |
tree | 8d38b5263c529b590c11c804bfd227dd01892d08 /src/image | |
parent | b84a58095f11ba3122b88847d1b0a73c57c1632c (diff) | |
download | go-36a3d4f3fea7bbb22be061fbe830420990cd3ecf.tar.gz go-36a3d4f3fea7bbb22be061fbe830420990cd3ecf.zip |
image: avoid sharing test images between tests and benchmarks
CL 136796 introduced benchmarks and refactored tests to use a
common list of test images. The tests now fail when run with
count > 2 since they rely on a fresh image each run.
Fix this by changing the list of test images to a list of test
image generator functions.
Change-Id: I5884c6bccba5e29bf84ee546fa501bc258379f42
Reviewed-on: https://go-review.googlesource.com/137295
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/image_test.go | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/image/image_test.go b/src/image/image_test.go index 6f49752a25..dfd8eb35a8 100644 --- a/src/image/image_test.go +++ b/src/image/image_test.go @@ -24,25 +24,27 @@ func cmp(cm color.Model, c0, c1 color.Color) bool { var testImages = []struct { name string - image image + image func() image }{ - {"rgba", NewRGBA(Rect(0, 0, 10, 10))}, - {"rgba64", NewRGBA64(Rect(0, 0, 10, 10))}, - {"nrgba", NewNRGBA(Rect(0, 0, 10, 10))}, - {"nrgba64", NewNRGBA64(Rect(0, 0, 10, 10))}, - {"alpha", NewAlpha(Rect(0, 0, 10, 10))}, - {"alpha16", NewAlpha16(Rect(0, 0, 10, 10))}, - {"gray", NewGray(Rect(0, 0, 10, 10))}, - {"gray16", NewGray16(Rect(0, 0, 10, 10))}, - {"paletted", NewPaletted(Rect(0, 0, 10, 10), color.Palette{ - Transparent, - Opaque, - })}, + {"rgba", func() image { return NewRGBA(Rect(0, 0, 10, 10)) }}, + {"rgba64", func() image { return NewRGBA64(Rect(0, 0, 10, 10)) }}, + {"nrgba", func() image { return NewNRGBA(Rect(0, 0, 10, 10)) }}, + {"nrgba64", func() image { return NewNRGBA64(Rect(0, 0, 10, 10)) }}, + {"alpha", func() image { return NewAlpha(Rect(0, 0, 10, 10)) }}, + {"alpha16", func() image { return NewAlpha16(Rect(0, 0, 10, 10)) }}, + {"gray", func() image { return NewGray(Rect(0, 0, 10, 10)) }}, + {"gray16", func() image { return NewGray16(Rect(0, 0, 10, 10)) }}, + {"paletted", func() image { + return NewPaletted(Rect(0, 0, 10, 10), color.Palette{ + Transparent, + Opaque, + }) + }}, } func TestImage(t *testing.T) { for _, tc := range testImages { - m := tc.image + m := tc.image() if !Rect(0, 0, 10, 10).Eq(m.Bounds()) { t.Errorf("%T: want bounds %v, got %v", m, Rect(0, 0, 10, 10), m.Bounds()) continue @@ -120,9 +122,11 @@ func Test16BitsPerColorChannel(t *testing.T) { func BenchmarkAt(b *testing.B) { for _, tc := range testImages { b.Run(tc.name, func(b *testing.B) { + m := tc.image() b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { - tc.image.At(4, 5) + m.At(4, 5) } }) } @@ -132,9 +136,11 @@ func BenchmarkSet(b *testing.B) { c := color.Gray{0xff} for _, tc := range testImages { b.Run(tc.name, func(b *testing.B) { + m := tc.image() b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { - tc.image.Set(4, 5, c) + m.Set(4, 5, c) } }) } |