resize_test.go 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package resize
  2. import (
  3. "image"
  4. "image/color"
  5. "runtime"
  6. "testing"
  7. )
  8. var img = image.NewGray16(image.Rect(0, 0, 3, 3))
  9. func init() {
  10. runtime.GOMAXPROCS(runtime.NumCPU())
  11. img.Set(1, 1, color.White)
  12. }
  13. func Test_Nearest(t *testing.T) {
  14. m := Resize(6, 0, img, NearestNeighbor)
  15. if m.At(2, 2) == m.At(3, 3) {
  16. t.Fail()
  17. }
  18. }
  19. func Test_Param1(t *testing.T) {
  20. m := Resize(0, 0, img, NearestNeighbor)
  21. if m.Bounds() != img.Bounds() {
  22. t.Fail()
  23. }
  24. }
  25. func Test_Param2(t *testing.T) {
  26. m := Resize(100, 0, img, NearestNeighbor)
  27. if m.Bounds() != image.Rect(0, 0, 100, 100) {
  28. t.Fail()
  29. }
  30. }
  31. func Test_ZeroImg(t *testing.T) {
  32. zeroImg := image.NewGray16(image.Rect(0, 0, 0, 0))
  33. m := Resize(0, 0, zeroImg, NearestNeighbor)
  34. if m.Bounds() != zeroImg.Bounds() {
  35. t.Fail()
  36. }
  37. }
  38. func Benchmark_BigResize(b *testing.B) {
  39. var m image.Image
  40. for i := 0; i < b.N; i++ {
  41. m = Resize(1000, 1000, img, Lanczos3)
  42. }
  43. m.At(0, 0)
  44. }