@@ -98,7 +98,7 @@ func TestHashCompute(t *testing.T) {
98
98
}
99
99
}
100
100
101
- func NilHashComputeTest (t * testing.T ) {
101
+ func TestNilHashCompute (t * testing.T ) {
102
102
hash , err := AverageHash (nil )
103
103
if err == nil {
104
104
t .Errorf ("Error should be got." )
@@ -124,6 +124,40 @@ func NilHashComputeTest(t *testing.T) {
124
124
}
125
125
}
126
126
127
+ func TestNilExtendHashCompute (t * testing.T ) {
128
+ hash , err := ExtAverageHash (nil , 8 , 8 )
129
+ if err == nil {
130
+ t .Errorf ("Error should be got." )
131
+ }
132
+ if hash != nil {
133
+ t .Errorf ("Nil hash should be got. but got %v" , hash )
134
+ }
135
+
136
+ hash , err = ExtDifferenceHash (nil , 8 , 8 )
137
+ if err == nil {
138
+ t .Errorf ("Error should be got." )
139
+ }
140
+ if hash != nil {
141
+ t .Errorf ("Nil hash should be got. but got %v" , hash )
142
+ }
143
+
144
+ hash , err = ExtPerceptionHash (nil , 8 , 8 )
145
+ if err == nil {
146
+ t .Errorf ("Error should be got." )
147
+ }
148
+ if hash != nil {
149
+ t .Errorf ("Nil hash should be got. but got %v" , hash )
150
+ }
151
+
152
+ hash , err = ExtPerceptionHash (nil , 8 , 9 )
153
+ if err == nil {
154
+ t .Errorf ("Error should be got." )
155
+ }
156
+ if hash != nil {
157
+ t .Errorf ("Nil hash should be got. but got %v" , hash )
158
+ }
159
+ }
160
+
127
161
func BenchmarkDistanceIdentical (b * testing.B ) {
128
162
h1 := & ImageHash {hash : 0xe48ae53c05e502f7 }
129
163
h2 := & ImageHash {hash : 0xe48ae53c05e502f7 }
@@ -295,3 +329,39 @@ func BenchmarkPerceptionHash(b *testing.B) {
295
329
}
296
330
}
297
331
}
332
+
333
+ func BenchmarkAverageHash (b * testing.B ) {
334
+ file1 , err := os .Open ("_examples/sample3.jpg" )
335
+ if err != nil {
336
+ b .Errorf ("%s" , err )
337
+ }
338
+ defer file1 .Close ()
339
+ img1 , err := jpeg .Decode (file1 )
340
+ if err != nil {
341
+ b .Errorf ("%s" , err )
342
+ }
343
+ for i := 0 ; i < b .N ; i ++ {
344
+ _ , err := ExtAverageHash (img1 , 8 , 8 )
345
+ if err != nil {
346
+ b .Errorf ("%s" , err )
347
+ }
348
+ }
349
+ }
350
+
351
+ func BenchmarkDiffrenceHash (b * testing.B ) {
352
+ file1 , err := os .Open ("_examples/sample3.jpg" )
353
+ if err != nil {
354
+ b .Errorf ("%s" , err )
355
+ }
356
+ defer file1 .Close ()
357
+ img1 , err := jpeg .Decode (file1 )
358
+ if err != nil {
359
+ b .Errorf ("%s" , err )
360
+ }
361
+ for i := 0 ; i < b .N ; i ++ {
362
+ _ , err := ExtDifferenceHash (img1 , 8 , 8 )
363
+ if err != nil {
364
+ b .Errorf ("%s" , err )
365
+ }
366
+ }
367
+ }
0 commit comments