Skip to content

Commit 16d31dc

Browse files
aclementsgopherbot
authored andcommitted
hash: use testhash.TestHash in all hash functions
For #69521 Change-Id: I4e056253f94ad421fcef12d21edaaaf2517b64c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/670179 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Austin Clements <[email protected]> Reviewed-by: qiu laidongfeng2 <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 3f7c0cc commit 16d31dc

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

src/hash/adler32/adler32_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ package adler32
66

77
import (
88
"encoding"
9+
"hash"
10+
"internal/testhash"
911
"io"
1012
"strings"
1113
"testing"
1214
)
1315

16+
func TestHashInterface(t *testing.T) {
17+
testhash.TestHash(t, func() hash.Hash { return New() })
18+
}
19+
1420
var golden = []struct {
1521
out uint32
1622
in string

src/hash/crc32/crc32_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding"
99
"fmt"
1010
"hash"
11+
"internal/testhash"
1112
"io"
1213
"math/rand"
1314
"testing"
@@ -23,6 +24,10 @@ func TestCastagnoliRace(t *testing.T) {
2324
ieee.Write([]byte("hello"))
2425
}
2526

27+
func TestHashInterface(t *testing.T) {
28+
testhash.TestHash(t, func() hash.Hash { return NewIEEE() })
29+
}
30+
2631
type test struct {
2732
ieee, castagnoli uint32
2833
in string

src/hash/crc64/crc64_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ package crc64
66

77
import (
88
"encoding"
9+
"hash"
10+
"internal/testhash"
911
"io"
1012
"testing"
1113
)
1214

15+
func TestCRC64Hash(t *testing.T) {
16+
testhash.TestHash(t, func() hash.Hash { return New(MakeTable(ISO)) })
17+
}
18+
1319
type test struct {
1420
outISO uint64
1521
outECMA uint64

src/hash/fnv/fnv_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,37 @@ import (
99
"encoding"
1010
"encoding/binary"
1111
"hash"
12+
"internal/testhash"
1213
"io"
1314
"testing"
1415
)
1516

17+
func TestHashInterface(t *testing.T) {
18+
type test struct {
19+
name string
20+
fn func() hash.Hash
21+
}
22+
fn32 := func(fn func() hash.Hash32) func() hash.Hash {
23+
return func() hash.Hash { return fn() }
24+
}
25+
fn64 := func(fn func() hash.Hash64) func() hash.Hash {
26+
return func() hash.Hash { return fn() }
27+
}
28+
tests := []test{
29+
{"32", fn32(New32)},
30+
{"32a", fn32(New32a)},
31+
{"64", fn64(New64)},
32+
{"64a", fn64(New64a)},
33+
{"128", New128},
34+
{"128a", New128a},
35+
}
36+
for _, test := range tests {
37+
t.Run(test.name, func(t *testing.T) {
38+
testhash.TestHash(t, test.fn)
39+
})
40+
}
41+
}
42+
1643
type golden struct {
1744
out []byte
1845
in string

src/hash/maphash/maphash_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"hash"
1111
"internal/asan"
12+
"internal/testhash"
1213
"math"
1314
"reflect"
1415
"strings"
@@ -455,6 +456,10 @@ func TestComparableAllocations(t *testing.T) {
455456
var _ hash.Hash = &Hash{}
456457
var _ hash.Hash64 = &Hash{}
457458

459+
func TestHashInterface(t *testing.T) {
460+
testhash.TestHash(t, func() hash.Hash { return new(Hash) })
461+
}
462+
458463
func benchmarkSize(b *testing.B, size int) {
459464
h := &Hash{}
460465
buf := make([]byte, size)

0 commit comments

Comments
 (0)