๐Ÿ“ฆ deluan / lookup

๐Ÿ“„ lookup_test.go ยท 67 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67package lookup

import (
	_ "image/png"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
)

func TestLookup(t *testing.T) {
	Convey("Given a GrayScale image", t, func() {
		img := loadImageGray("testdata/cyclopst1.png")
		l := NewLookup(img)

		Convey("When I search using a grayscale template", func() {
			template := loadImageGray("testdata/cyclopst3.png")

			Convey("It finds the template", func() {
				pp, _ := l.FindAll(template, 0.9)
				So(pp, ShouldHaveLength, 1)
				So(pp[0].X, ShouldEqual, 21)
				So(pp[0].Y, ShouldEqual, 7)
				So(pp[0].G, ShouldBeGreaterThan, 0.9)
			})
		})

		Convey("When I search using a color template", func() {
			template := loadImageColor("testdata/cyclopst3.png")

			Convey("It finds the template", func() {
				pp, _ := l.FindAll(template, 0.9)
				So(pp, ShouldHaveLength, 1)
				So(pp[0].X, ShouldEqual, 21)
				So(pp[0].Y, ShouldEqual, 7)
				So(pp[0].G, ShouldBeGreaterThan, 0.9)
			})
		})
	})

	Convey("Given a Color image", t, func() {
		img := loadImageColor("testdata/cyclopst1.png")
		l := NewLookupColor(img)

		Convey("When I search using a color template", func() {
			template := loadImageColor("testdata/cyclopst3.png")

			Convey("It finds the template", func() {
				pp, _ := l.FindAll(template, 0.9)
				So(pp, ShouldHaveLength, 1)
				So(pp[0].X, ShouldEqual, 21)
				So(pp[0].Y, ShouldEqual, 7)
				So(pp[0].G, ShouldBeGreaterThan, 0.9)
			})
		})
		Convey("When I search using a grayscale template", func() {
			template := loadImageGray("testdata/cyclopst3.png")

			Convey("It returns an error", func() {
				_, err := l.FindAll(template, 0.9)
				println(err.Error())
				So(err, ShouldNotBeNil)
			})
		})

	})
}