]> Cypherpunks repositories - gostls13.git/commitdiff
hash: use testhash.TestHash in all hash functions
authorAustin Clements <austin@google.com>
Mon, 5 May 2025 21:12:42 +0000 (17:12 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 8 May 2025 23:41:48 +0000 (16:41 -0700)
For #69521

Change-Id: I4e056253f94ad421fcef12d21edaaaf2517b64c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/670179
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: qiu laidongfeng2 <2645477756@qq.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
src/hash/adler32/adler32_test.go
src/hash/crc32/crc32_test.go
src/hash/crc64/crc64_test.go
src/hash/fnv/fnv_test.go
src/hash/maphash/maphash_test.go

index ebb9a438a63f878abc131225589271bfb46ab356..d42558f31dffd49690ab93c36fb609a5adb45594 100644 (file)
@@ -6,11 +6,17 @@ package adler32
 
 import (
        "encoding"
+       "hash"
+       "internal/testhash"
        "io"
        "strings"
        "testing"
 )
 
+func TestHashInterface(t *testing.T) {
+       testhash.TestHash(t, func() hash.Hash { return New() })
+}
+
 var golden = []struct {
        out       uint32
        in        string
index 10c28f9533bb28c83a88635efc035844956c4bbf..40acd7da4f84ec1b738fc45888f508fc38a228d7 100644 (file)
@@ -8,6 +8,7 @@ import (
        "encoding"
        "fmt"
        "hash"
+       "internal/testhash"
        "io"
        "math/rand"
        "testing"
@@ -23,6 +24,10 @@ func TestCastagnoliRace(t *testing.T) {
        ieee.Write([]byte("hello"))
 }
 
+func TestHashInterface(t *testing.T) {
+       testhash.TestHash(t, func() hash.Hash { return NewIEEE() })
+}
+
 type test struct {
        ieee, castagnoli    uint32
        in                  string
index 06c428c81f007993ce1653455c10d7ccad7fae1c..d1154d5d544ad0c48126522d46ed129480a5bae3 100644 (file)
@@ -6,10 +6,16 @@ package crc64
 
 import (
        "encoding"
+       "hash"
+       "internal/testhash"
        "io"
        "testing"
 )
 
+func TestCRC64Hash(t *testing.T) {
+       testhash.TestHash(t, func() hash.Hash { return New(MakeTable(ISO)) })
+}
+
 type test struct {
        outISO        uint64
        outECMA       uint64
index 4219460e46fc8556adc523c1a13f3127f2ad0594..20e530032a1d8549cabdbc63d9e334175193aa07 100644 (file)
@@ -9,10 +9,37 @@ import (
        "encoding"
        "encoding/binary"
        "hash"
+       "internal/testhash"
        "io"
        "testing"
 )
 
+func TestHashInterface(t *testing.T) {
+       type test struct {
+               name string
+               fn   func() hash.Hash
+       }
+       fn32 := func(fn func() hash.Hash32) func() hash.Hash {
+               return func() hash.Hash { return fn() }
+       }
+       fn64 := func(fn func() hash.Hash64) func() hash.Hash {
+               return func() hash.Hash { return fn() }
+       }
+       tests := []test{
+               {"32", fn32(New32)},
+               {"32a", fn32(New32a)},
+               {"64", fn64(New64)},
+               {"64a", fn64(New64a)},
+               {"128", New128},
+               {"128a", New128a},
+       }
+       for _, test := range tests {
+               t.Run(test.name, func(t *testing.T) {
+                       testhash.TestHash(t, test.fn)
+               })
+       }
+}
+
 type golden struct {
        out       []byte
        in        string
index 4a85c8a6acadf41a986f4a149c3506670534798b..0774c1c3ced7c0bbd4bdff3ec4d4cd020d1b91ea 100644 (file)
@@ -9,6 +9,7 @@ import (
        "fmt"
        "hash"
        "internal/asan"
+       "internal/testhash"
        "math"
        "reflect"
        "strings"
@@ -455,6 +456,10 @@ func TestComparableAllocations(t *testing.T) {
 var _ hash.Hash = &Hash{}
 var _ hash.Hash64 = &Hash{}
 
+func TestHashInterface(t *testing.T) {
+       testhash.TestHash(t, func() hash.Hash { return new(Hash) })
+}
+
 func benchmarkSize(b *testing.B, size int) {
        h := &Hash{}
        buf := make([]byte, size)