2012-08-02 21:59:40 +02:00
|
|
|
package resize
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2012-08-03 18:12:26 +02:00
|
|
|
var img = image.NewGray16(image.Rect(0, 0, 3, 3))
|
|
|
|
|
2012-08-02 21:59:40 +02:00
|
|
|
func Test_Nearest(t *testing.T) {
|
2012-08-03 18:12:26 +02:00
|
|
|
img.Set(1, 1, color.White)
|
|
|
|
|
2012-08-08 21:32:51 +02:00
|
|
|
m, err := Resize(6, -1, img, NearestNeighbor)
|
2012-08-03 18:12:26 +02:00
|
|
|
|
2012-08-08 21:32:51 +02:00
|
|
|
if err != nil || m.At(2, 2) != m.At(3, 3) {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param1(t *testing.T) {
|
2012-08-08 21:32:51 +02:00
|
|
|
m, err := Resize(-1, -1, img, NearestNeighbor)
|
|
|
|
if err != nil || m.Bounds() != img.Bounds() {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param2(t *testing.T) {
|
2012-08-08 21:32:51 +02:00
|
|
|
_, err := Resize(-100, -1, img, NearestNeighbor)
|
|
|
|
if err == nil {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Param3(t *testing.T) {
|
2012-08-08 21:32:51 +02:00
|
|
|
m, err := Resize(0, -1, img, NearestNeighbor)
|
|
|
|
if err != nil || m.Bounds() != image.Rect(0, 0, 0, 0) {
|
2012-08-03 18:12:26 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ZeroImg(t *testing.T) {
|
|
|
|
zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
|
|
|
|
|
2012-08-08 21:32:51 +02:00
|
|
|
m, err := Resize(-1, -1, zeroImg, NearestNeighbor)
|
|
|
|
if err != nil || m.Bounds() != zeroImg.Bounds() {
|
2012-08-02 21:59:40 +02:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|