all: Add more test (#30)
* hashcompute_test: Add benchmark * all: Add more test
This commit is contained in:
parent
14aa1e136f
commit
6392b0bac9
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user