Skip to content

Commit 6392b0b

Browse files
authored
all: Add more test (#30)
* hashcompute_test: Add benchmark * all: Add more test
1 parent 14aa1e1 commit 6392b0b

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func main() {
5858

5959
## Release Note
6060

61+
### v1.0.1
62+
- Perception/ExtPerception hash creation times are reduced
63+
6164
### v1.0.0
6265
**IMPORTANT**
6366
goimagehash v1.0.0 does not have compatible with the before version for future features

hashcompute_test.go

+71-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestHashCompute(t *testing.T) {
9898
}
9999
}
100100

101-
func NilHashComputeTest(t *testing.T) {
101+
func TestNilHashCompute(t *testing.T) {
102102
hash, err := AverageHash(nil)
103103
if err == nil {
104104
t.Errorf("Error should be got.")
@@ -124,6 +124,40 @@ func NilHashComputeTest(t *testing.T) {
124124
}
125125
}
126126

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+
127161
func BenchmarkDistanceIdentical(b *testing.B) {
128162
h1 := &ImageHash{hash: 0xe48ae53c05e502f7}
129163
h2 := &ImageHash{hash: 0xe48ae53c05e502f7}
@@ -295,3 +329,39 @@ func BenchmarkPerceptionHash(b *testing.B) {
295329
}
296330
}
297331
}
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

Comments
 (0)