resize/resize_test.go

73 lines
1.3 KiB
Go
Raw Normal View History

2012-08-02 19:59:40 +00:00
package resize
import (
"image"
"image/color"
"runtime"
2012-08-02 19:59:40 +00:00
"testing"
)
2012-08-03 16:12:26 +00:00
var img = image.NewGray16(image.Rect(0, 0, 3, 3))
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
2012-08-03 16:12:26 +00:00
img.Set(1, 1, color.White)
}
2012-08-03 16:12:26 +00:00
func Test_Nearest(t *testing.T) {
m := Resize(6, 0, img, NearestNeighbor)
if m.At(1, 1) == m.At(2, 2) {
2012-08-03 16:12:26 +00:00
t.Fail()
}
}
func Test_Param1(t *testing.T) {
m := Resize(0, 0, img, NearestNeighbor)
if m.Bounds() != img.Bounds() {
2012-08-03 16:12:26 +00:00
t.Fail()
}
}
func Test_Param2(t *testing.T) {
m := Resize(100, 0, img, NearestNeighbor)
if m.Bounds() != image.Rect(0, 0, 100, 100) {
2012-08-03 16:12:26 +00:00
t.Fail()
}
}
func Test_ZeroImg(t *testing.T) {
zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
m := Resize(0, 0, zeroImg, NearestNeighbor)
if m.Bounds() != zeroImg.Bounds() {
2012-08-02 19:59:40 +00:00
t.Fail()
}
}
2013-03-10 09:58:08 +00:00
func Test_CorrectResize(t *testing.T) {
2013-03-10 10:55:50 +00:00
zeroImg := image.NewGray16(image.Rect(0, 0, 256, 256))
2013-03-10 09:58:08 +00:00
m := Resize(60, 0, zeroImg, NearestNeighbor)
2013-03-10 10:55:50 +00:00
if m.Bounds() != image.Rect(0, 0, 60, 60) {
2013-03-10 09:58:08 +00:00
t.Fail()
}
}
func Benchmark_BigResize(b *testing.B) {
var m image.Image
for i := 0; i < b.N; i++ {
m = Resize(1000, 1000, img, Lanczos3)
}
m.At(0, 0)
}
func Benchmark_Reduction(b *testing.B) {
largeImg := image.NewRGBA(image.Rect(0, 0, 1000, 1000))
var m image.Image
for i := 0; i < b.N; i++ {
m = Resize(300, 300, largeImg, Bicubic)
}
m.At(0, 0)
}