resize_test.go 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 init() {
  9. img.Set(1, 1, color.White)
  10. }
  11. func Test_Nearest(t *testing.T) {
  12. m := Resize(6, 0, img, NearestNeighbor)
  13. if m.At(2, 2) == m.At(3, 3) {
  14. t.Fail()
  15. }
  16. }
  17. func Test_Param1(t *testing.T) {
  18. m := Resize(0, 0, img, NearestNeighbor)
  19. if m.Bounds() != img.Bounds() {
  20. t.Fail()
  21. }
  22. }
  23. func Test_Param2(t *testing.T) {
  24. m := Resize(100, 0, img, NearestNeighbor)
  25. if m.Bounds() != image.Rect(0, 0, 100, 100) {
  26. t.Fail()
  27. }
  28. }
  29. func Test_ZeroImg(t *testing.T) {
  30. zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
  31. m := Resize(0, 0, zeroImg, NearestNeighbor)
  32. if m.Bounds() != zeroImg.Bounds() {
  33. t.Fail()
  34. }
  35. }
  36. func Benchmark_BigResize(b *testing.B) {
  37. m := Resize(1000, 1000, img, Lanczos3)
  38. m.At(0, 0)
  39. }