Skip to content

Commit

Permalink
Checks for all Interpolation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3103 committed Jan 29, 2020
1 parent 644b496 commit af66474
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,45 @@ import (
)

var img = image.NewNRGBA(image.Rect(0, 0, 5, 5))
var kernels = []InterpolationFunction{CatmullRom, Bilinear}

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
img.Set(5, 5, color.Black)
}

func Test_SameSize(t *testing.T) {
newImg, _ := Resize(img, 0, 0, CatmullRom)
if newImg.Bounds() != img.Bounds() {
log.Print(img.Bounds().Dx(), "x", img.Bounds().Dy())
log.Print(newImg.Bounds().Dx(), "x", newImg.Bounds().Dy())
t.Fail()
for _, kernel := range kernels {
newImg, _ := Resize(img, 0, 0, kernel)
if newImg.Bounds() != img.Bounds() {
log.Print(img.Bounds().Dx(), "x", img.Bounds().Dy())
log.Print(newImg.Bounds().Dx(), "x", newImg.Bounds().Dy())
t.Fail()
}
}
}

func Test_Height(t *testing.T) {
newImg, err := Resize(img, 0, 100, CatmullRom)
if err != nil || newImg.Bounds().Dy() != 100 || newImg.Bounds().Dx() != 100 {
t.Fail()
for _, kernel := range kernels {
newImg, err := Resize(img, 0, 100, kernel)
if err != nil || newImg.Bounds().Dy() != 100 || newImg.Bounds().Dx() != 100 {
t.Fail()
}
}
}
func Test_Width(t *testing.T) {
newImg, err := Resize(img, 200, 0, CatmullRom)
if err != nil || newImg.Bounds().Dy() != 200 || newImg.Bounds().Dx() != 200 {
t.Fail()
for _, kernel := range kernels {
newImg, err := Resize(img, 200, 0, kernel)
if err != nil || newImg.Bounds().Dy() != 200 || newImg.Bounds().Dx() != 200 {
t.Fail()
}
}
}
func Test_WidthAndHeight(t *testing.T) {
newImg, err := Resize(img, 300, 300, CatmullRom)
if err != nil || newImg.Bounds() != image.Rect(0, 0, 300, 300) {
t.Fail()
for _, kernel := range kernels {
newImg, err := Resize(img, 300, 300, kernel)
if err != nil || newImg.Bounds() != image.Rect(0, 0, 300, 300) {
t.Fail()
}
}
}

0 comments on commit af66474

Please sign in to comment.