projector_test.go 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2011 The Graphics-Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package detect
  5. import (
  6. "image"
  7. "reflect"
  8. "testing"
  9. )
  10. type projectorTest struct {
  11. dst image.Rectangle
  12. src image.Rectangle
  13. pdst image.Rectangle
  14. psrc image.Rectangle
  15. }
  16. var projectorTests = []projectorTest{
  17. {
  18. image.Rect(0, 0, 6, 6),
  19. image.Rect(0, 0, 2, 2),
  20. image.Rect(0, 0, 6, 6),
  21. image.Rect(0, 0, 2, 2),
  22. },
  23. {
  24. image.Rect(0, 0, 6, 6),
  25. image.Rect(0, 0, 2, 2),
  26. image.Rect(3, 3, 6, 6),
  27. image.Rect(1, 1, 2, 2),
  28. },
  29. {
  30. image.Rect(30, 30, 40, 40),
  31. image.Rect(10, 10, 20, 20),
  32. image.Rect(32, 33, 34, 37),
  33. image.Rect(12, 13, 14, 17),
  34. },
  35. }
  36. func TestProjector(t *testing.T) {
  37. for i, tt := range projectorTests {
  38. pr := newProjector(tt.dst, tt.src)
  39. res := pr.rect(tt.psrc)
  40. if !reflect.DeepEqual(res, tt.pdst) {
  41. t.Errorf("%d: got %v want %v", i, res, tt.pdst)
  42. }
  43. }
  44. }