PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/graphics/detect/projector_test.go

https://code.google.com/p/graphics-go/
Go | 49 lines | 41 code | 5 blank | 3 comment | 2 complexity | bb54103c71f0a59c9810becd5c8e39c2 MD5 | raw file
 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
 5package detect
 6
 7import (
 8	"image"
 9	"reflect"
10	"testing"
11)
12
13type projectorTest struct {
14	dst  image.Rectangle
15	src  image.Rectangle
16	pdst image.Rectangle
17	psrc image.Rectangle
18}
19
20var 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
41func 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}