-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_test.go
69 lines (56 loc) · 1.56 KB
/
pixel_test.go
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
67
68
69
package ipare
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/gotokatsuya/ipare/algorithm/pixel"
"github.com/gotokatsuya/ipare/util"
)
func TestSamePixel(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
algorithm PixelAlgorithm
img1 string
img2 string
}{
{"Part", pixel.NewPart(), "testdata/sample1.jpg", "testdata/sample1.jpg"},
{"Block", pixel.NewBlock(), "testdata/sample1.jpg", "testdata/sample1.jpg"},
}
for _, tt := range tests {
target := fmt.Sprintf("%v", tt.name)
pixel := NewPixel()
pixel.Algorithm = tt.algorithm
img1, err := util.Open(tt.img1)
assert.NoError(err, target)
img2, err := util.Open(tt.img2)
assert.NoError(err, target)
distance := pixel.Compare(img1, img2)
assert.Equal(0, distance, target)
t.Logf("Distance = %d. %s", distance, target)
}
}
func TestUnSamePixel(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
algorithm PixelAlgorithm
img1 string
img2 string
}{
{"Part", pixel.NewPart(), "testdata/sample1.jpg", "testdata/sample2.jpg"},
{"Block", pixel.NewBlock(), "testdata/sample1.jpg", "testdata/sample2.jpg"},
}
for _, tt := range tests {
target := fmt.Sprintf("%v", tt.name)
pixel := NewPixel()
pixel.Algorithm = tt.algorithm
img1, err := util.Open(tt.img1)
assert.NoError(err, target)
img2, err := util.Open(tt.img2)
assert.NoError(err, target)
distance := pixel.Compare(img1, img2)
assert.NotEqual(0, distance, target)
t.Logf("Distance = %d. %s", distance, target)
}
}