No Description

nearest_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright (c) 2014, Charlie Vieth <charlie.vieth@gmail.com>
  3. Permission to use, copy, modify, and/or distribute this software for any purpose
  4. with or without fee is hereby granted, provided that the above copyright notice
  5. and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  7. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  8. FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  9. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  10. OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  11. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  12. THIS SOFTWARE.
  13. */
  14. package resize
  15. import "testing"
  16. func Test_FloatToUint8(t *testing.T) {
  17. var testData = []struct {
  18. in float32
  19. expected uint8
  20. }{
  21. {0, 0},
  22. {255, 255},
  23. {128, 128},
  24. {1, 1},
  25. {256, 255},
  26. }
  27. for _, test := range testData {
  28. actual := floatToUint8(test.in)
  29. if actual != test.expected {
  30. t.Fail()
  31. }
  32. }
  33. }
  34. func Test_FloatToUint16(t *testing.T) {
  35. var testData = []struct {
  36. in float32
  37. expected uint16
  38. }{
  39. {0, 0},
  40. {65535, 65535},
  41. {128, 128},
  42. {1, 1},
  43. {65536, 65535},
  44. }
  45. for _, test := range testData {
  46. actual := floatToUint16(test.in)
  47. if actual != test.expected {
  48. t.Fail()
  49. }
  50. }
  51. }