-
Notifications
You must be signed in to change notification settings - Fork 4
/
dtc_test.go
44 lines (40 loc) · 989 Bytes
/
dtc_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
package phash
import (
_ "embed"
"image"
"strings"
"testing"
)
//go:embed testdata/lena/l_hires.jpg
var lHiresJPGFile string
var (
lHiresJPG, _, _ = image.Decode(strings.NewReader(lHiresJPGFile))
knownLHiresHash = "0100011111110101011000000111111011000110010001110001010100011000"
)
func TestDTC(t *testing.T) {
type args struct {
img image.Image
}
tests := []struct {
name string
args args
wantPhash uint64
}{
// This test is quite handy, because I could find the expected
// result in the research papers. A picture a bit more SFW
// would have been better though.
{name: "lena jpg",
args: args{img: lHiresJPG},
wantPhash: parseBinary(knownLHiresHash)},
{name: "zero",
args: args{img: nil},
wantPhash: 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotPhash := DTC(tt.args.img); gotPhash != tt.wantPhash {
t.Errorf("DTC() =\n%064b\nwant :\n%064b", gotPhash, tt.wantPhash)
}
})
}
}