all: Add more test (#30)

* hashcompute_test: Add benchmark

* all: Add more test
This commit is contained in:
Dong-hee Na 2019-03-19 23:10:52 +09:00 committed by GitHub
parent 14aa1e136f
commit 6392b0bac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 1 deletions

View File

@ -58,6 +58,9 @@ func main() {
## Release Note
### v1.0.1
- Perception/ExtPerception hash creation times are reduced
### v1.0.0
**IMPORTANT**
goimagehash v1.0.0 does not have compatible with the before version for future features

View File

@ -98,7 +98,7 @@ func TestHashCompute(t *testing.T) {
}
}
func NilHashComputeTest(t *testing.T) {
func TestNilHashCompute(t *testing.T) {
hash, err := AverageHash(nil)
if err == nil {
t.Errorf("Error should be got.")
@ -124,6 +124,40 @@ func NilHashComputeTest(t *testing.T) {
}
}
func TestNilExtendHashCompute(t *testing.T) {
hash, err := ExtAverageHash(nil, 8, 8)
if err == nil {
t.Errorf("Error should be got.")
}
if hash != nil {
t.Errorf("Nil hash should be got. but got %v", hash)
}
hash, err = ExtDifferenceHash(nil, 8, 8)
if err == nil {
t.Errorf("Error should be got.")
}
if hash != nil {
t.Errorf("Nil hash should be got. but got %v", hash)
}
hash, err = ExtPerceptionHash(nil, 8, 8)
if err == nil {
t.Errorf("Error should be got.")
}
if hash != nil {
t.Errorf("Nil hash should be got. but got %v", hash)
}
hash, err = ExtPerceptionHash(nil, 8, 9)
if err == nil {
t.Errorf("Error should be got.")
}
if hash != nil {
t.Errorf("Nil hash should be got. but got %v", hash)
}
}
func BenchmarkDistanceIdentical(b *testing.B) {
h1 := &ImageHash{hash: 0xe48ae53c05e502f7}
h2 := &ImageHash{hash: 0xe48ae53c05e502f7}
@ -295,3 +329,39 @@ func BenchmarkPerceptionHash(b *testing.B) {
}
}
}
func BenchmarkAverageHash(b *testing.B) {
file1, err := os.Open("_examples/sample3.jpg")
if err != nil {
b.Errorf("%s", err)
}
defer file1.Close()
img1, err := jpeg.Decode(file1)
if err != nil {
b.Errorf("%s", err)
}
for i := 0; i < b.N; i++ {
_, err := ExtAverageHash(img1, 8, 8)
if err != nil {
b.Errorf("%s", err)
}
}
}
func BenchmarkDiffrenceHash(b *testing.B) {
file1, err := os.Open("_examples/sample3.jpg")
if err != nil {
b.Errorf("%s", err)
}
defer file1.Close()
img1, err := jpeg.Decode(file1)
if err != nil {
b.Errorf("%s", err)
}
for i := 0; i < b.N; i++ {
_, err := ExtDifferenceHash(img1, 8, 8)
if err != nil {
b.Errorf("%s", err)
}
}
}