converter_test.go 621 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package resize
  2. import (
  3. "testing"
  4. )
  5. func Test_ClampUint8(t *testing.T) {
  6. var testData = []struct {
  7. in int32
  8. expected uint8
  9. }{
  10. {0, 0},
  11. {255, 255},
  12. {128, 128},
  13. {-2, 0},
  14. {256, 255},
  15. }
  16. for _, test := range testData {
  17. actual := clampUint8(test.in)
  18. if actual != test.expected {
  19. t.Fail()
  20. }
  21. }
  22. }
  23. func Test_ClampUint16(t *testing.T) {
  24. var testData = []struct {
  25. in int64
  26. expected uint16
  27. }{
  28. {0, 0},
  29. {65535, 65535},
  30. {128, 128},
  31. {-2, 0},
  32. {65536, 65535},
  33. }
  34. for _, test := range testData {
  35. actual := clampUint16(test.in)
  36. if actual != test.expected {
  37. t.Fail()
  38. }
  39. }
  40. }