From 6392b0bac9bf3b0a5ff2ff0413aae3c87ae1b6df Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 19 Mar 2019 23:10:52 +0900 Subject: [PATCH] all: Add more test (#30) * hashcompute_test: Add benchmark * all: Add more test --- README.md | 3 ++ hashcompute_test.go | 72 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60a6ffe..394bc00 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/hashcompute_test.go b/hashcompute_test.go index 575d84d..83711a9 100644 --- a/hashcompute_test.go +++ b/hashcompute_test.go @@ -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) + } + } +}