Skip to content

Commit

Permalink
all: Add more test (#30)
Browse files Browse the repository at this point in the history
* hashcompute_test: Add benchmark

* all: Add more test
  • Loading branch information
corona10 authored Mar 19, 2019
1 parent 14aa1e1 commit 6392b0b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 71 additions & 1 deletion hashcompute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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}
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 6392b0b

Please sign in to comment.