Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Jan 21, 2024
1 parent 5d701a4 commit f6a5fda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion imagehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"io"
)

var errNoOther = errors.New("other should not be nil")

// Kind describes the kinds of hash.
type Kind int

Expand Down Expand Up @@ -55,7 +57,7 @@ func (h *ImageHash) Bits() int {
// Distance method returns a distance between two hashes.
func (h *ImageHash) Distance(other *ImageHash) (int, error) {
if other == nil {
return -1, errors.New("other should not be nil")
return -1, errNoOther
}
if h.GetKind() != other.GetKind() {
return -1, errors.New("Image hashes's kind should be identical")
Expand Down
5 changes: 2 additions & 3 deletions imagehash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ func TestNewImageHash(t *testing.T) {
func TestNil(t *testing.T) {
hash := NewImageHash(0, AHash)
dis, err := hash.Distance(nil)
expectedError := errors.New("other should not be nil")
if err != nil && err.Error() != expectedError.Error() {
t.Errorf("Expected err %s, actual %s", expectedError, err)
if !errors.Is(err, errNoOther) {

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.9.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.11.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.12.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.10.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.11.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.12.x, ubuntu-latest)

undefined: errors.Is

Check failure on line 62 in imagehash_test.go

View workflow job for this annotation

GitHub Actions / test (1.11.x, ubuntu-latest)

undefined: errors.Is
t.Errorf("Expected err %s, actual %s", errNoOther, err)
}
if dis != -1 {
t.Errorf("Distance is expected as %d but got %d", -1, dis)
Expand Down

0 comments on commit f6a5fda

Please sign in to comment.