github.com/aloncn/graphics-go@v0.0.1/graphics/detect/projector_test.go (about) 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 5 package detect 6 7 import ( 8 "image" 9 "reflect" 10 "testing" 11 ) 12 13 type projectorTest struct { 14 dst image.Rectangle 15 src image.Rectangle 16 pdst image.Rectangle 17 psrc image.Rectangle 18 } 19 20 var projectorTests = []projectorTest{ 21 { 22 image.Rect(0, 0, 6, 6), 23 image.Rect(0, 0, 2, 2), 24 image.Rect(0, 0, 6, 6), 25 image.Rect(0, 0, 2, 2), 26 }, 27 { 28 image.Rect(0, 0, 6, 6), 29 image.Rect(0, 0, 2, 2), 30 image.Rect(3, 3, 6, 6), 31 image.Rect(1, 1, 2, 2), 32 }, 33 { 34 image.Rect(30, 30, 40, 40), 35 image.Rect(10, 10, 20, 20), 36 image.Rect(32, 33, 34, 37), 37 image.Rect(12, 13, 14, 17), 38 }, 39 } 40 41 func TestProjector(t *testing.T) { 42 for i, tt := range projectorTests { 43 pr := newProjector(tt.dst, tt.src) 44 res := pr.rect(tt.psrc) 45 if !reflect.DeepEqual(res, tt.pdst) { 46 t.Errorf("%d: got %v want %v", i, res, tt.pdst) 47 } 48 } 49 }