resize_test.go 909 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package resize
  2. import (
  3. "image"
  4. "image/color"
  5. "testing"
  6. )
  7. var img = image.NewGray16(image.Rect(0, 0, 3, 3))
  8. func Test_Nearest(t *testing.T) {
  9. img.Set(1, 1, color.White)
  10. m, err := Resize(6, -1, img, NearestNeighbor)
  11. if err != nil || m.At(2, 2) != m.At(3, 3) {
  12. t.Fail()
  13. }
  14. }
  15. func Test_Param1(t *testing.T) {
  16. m, err := Resize(-1, -1, img, NearestNeighbor)
  17. if err != nil || m.Bounds() != img.Bounds() {
  18. t.Fail()
  19. }
  20. }
  21. func Test_Param2(t *testing.T) {
  22. _, err := Resize(-100, -1, img, NearestNeighbor)
  23. if err == nil {
  24. t.Fail()
  25. }
  26. }
  27. func Test_Param3(t *testing.T) {
  28. m, err := Resize(0, -1, img, NearestNeighbor)
  29. if err != nil || m.Bounds() != image.Rect(0, 0, 0, 0) {
  30. t.Fail()
  31. }
  32. }
  33. func Test_ZeroImg(t *testing.T) {
  34. zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
  35. m, err := Resize(-1, -1, zeroImg, NearestNeighbor)
  36. if err != nil || m.Bounds() != zeroImg.Bounds() {
  37. t.Fail()
  38. }
  39. }