-
Notifications
You must be signed in to change notification settings - Fork 1
/
phash_test.go
50 lines (45 loc) · 1.36 KB
/
phash_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
package phash
import (
"testing"
)
var dctTestData = []struct {
filename string
hash uint64
}{
{"testdata/gif/gopher.gif", 10631249863007147461},
{"testdata/jpg/gopher.jpg", 10631249863007147461},
{"testdata/jpg/gopher-blur.jpg", 10631249863007147461},
{"testdata/jpg/gopher-rotate.jpg", 10631249863007147461},
{"testdata/jpg/gopher-flip.jpg", 9364791847115625850},
{"testdata/jpg/gopher-flop.jpg", 17752165113623953620},
{"testdata/jpg/gopher-shave.jpg", 11459704921468884741},
{"testdata/png/gopher.png", 10631249863007147461},
{"testdata/png/navalny.png", 7471994969771757134},
}
var hammingTestData = []struct {
h1, h2 uint64
distance int
}{
{10631249863007147461, 10631249863007147461, 0},
{10631249863007147461, 9364791847115625850, 32},
{10631249863007147461, 17752165113623953620, 32},
{10631249863007147461, 11459704921468884741, 16},
}
func TestImageHashDCT(t *testing.T) {
for _, tc := range dctTestData {
hash, err := ImageHashDCT(tc.filename)
if err != nil {
t.Errorf("ImageHashDCT(%s): %v", tc.filename, err)
} else if hash != tc.hash {
t.Errorf("ImageHashDCT(%s): want %d, got %d", tc.filename, tc.hash, hash)
}
}
}
func TestHammingDistance(t *testing.T) {
for _, tc := range hammingTestData {
distance := HammingDistance(tc.h1, tc.h2)
if distance != tc.distance {
t.Errorf("want %d, got %d", tc.distance, distance)
}
}
}