2012-08-02 19:59:40 +00:00
|
|
|
package resize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2012-08-03 16:12:26 +00:00
|
|
|
var img = image.NewGray16(image.Rect(0, 0, 3, 3))
|
|
|
|
|
2012-08-31 22:21:10 +00:00
|
|
|
func init() {
|
2012-08-03 16:12:26 +00:00
|
|
|
img.Set(1, 1, color.White)
|
2012-08-31 22:21:10 +00:00
|
|
|
}
|
2012-08-03 16:12:26 +00:00
|
|
|
|
2012-08-31 22:21:10 +00:00
|
|
|
func Test_Nearest(t *testing.T) {
|
2012-08-09 16:56:42 +00:00
|
|
|
m := Resize(6, 0, img, NearestNeighbor)
|
2012-09-15 17:30:32 +00:00
|
|
|
if m.At(2, 2) == m.At(3, 3) {
|
2012-08-03 16:12:26 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param1(t *testing.T) {
|
2012-08-09 16:56:42 +00:00
|
|
|
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) {
|
2012-08-09 16:56:42 +00:00
|
|
|
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))
|
|
|
|
|
2012-08-09 16:56:42 +00:00
|
|
|
m := Resize(0, 0, zeroImg, NearestNeighbor)
|
|
|
|
if m.Bounds() != zeroImg.Bounds() {
|
2012-08-02 19:59:40 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2012-08-31 22:21:10 +00:00
|
|
|
|
|
|
|
func Benchmark_BigResize(b *testing.B) {
|
|
|
|
m := Resize(1000, 1000, img, Lanczos3)
|
|
|
|
m.At(0, 0)
|
|
|
|
}
|