-
Notifications
You must be signed in to change notification settings - Fork 4
/
ahash_test.go
71 lines (65 loc) · 1.33 KB
/
ahash_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
70
71
package imgsim
import (
"image"
"image/png"
"os"
"testing"
)
func TestAverageHash(t *testing.T) {
imgfile, err := os.Open("assets/gopher.png")
defer imgfile.Close()
if err != nil {
t.Errorf("failed to open image: %s", err)
}
img, err := png.Decode(imgfile)
if err != nil {
t.Errorf("failed to decode image: %s", err)
}
type args struct {
img image.Image
}
tests := []struct {
name string
args args
want Hash
}{
{"gopher image", args{img}, 9331034559709847552},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := AverageHash(tt.args.img); got != tt.want {
t.Errorf("AverageHash() = %v, want %v", got, tt.want)
}
})
}
}
func Test_mean(t *testing.T) {
imgfile, err := os.Open("assets/gopher.png")
defer imgfile.Close()
if err != nil {
t.Errorf("failed to open image: %s", err)
}
img, err := png.Decode(imgfile)
if err != nil {
t.Errorf("failed to decode image: %s", err)
}
emptyimg := image.NewGray(image.Rectangle{})
type args struct {
img image.Image
}
tests := []struct {
name string
args args
want uint32
}{
{"gopher image", args{img}, 9872},
{"0x0 image", args{emptyimg}, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := mean(tt.args.img); got != tt.want {
t.Errorf("mean() = %v, want %v", got, tt.want)
}
})
}
}