mirror of https://github.com/golang/go.git
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 <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>
This commit is contained in:
parent
3f7c0cc73c
commit
16d31dcc83
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue