checksum/hash/murmur3_32_test.go

58 lines
909 B
Go

package hash
import (
"github.com/tursom/checksum/assert"
"github.com/twmb/murmur3"
"hash"
"testing"
)
func TestMurmur332_Finish(t *testing.T) {
type fields struct {
d hash.Hash
}
tests := []struct {
name string
fields fields
builder func(m *Murmur332)
want []byte
}{
{
"nil",
fields{},
nil,
murmur3.New32().Sum(nil),
},
{
"hello",
fields{},
func(m *Murmur332) {
m.Append([]byte("hello"))
},
murmur332Sum([]byte("hello")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Murmur332{
d: tt.fields.d,
}
if tt.builder != nil {
tt.builder(m)
}
assert.Equals(t, m.Finish(), tt.want)
})
}
}
func murmur332Sum(b []byte) []byte {
h := murmur3.New32()
_, _ = h.Write(b)
return h.Sum(nil)
}
func TestMurmur332_String(t *testing.T) {
assert.Equals(t, (&Murmur332{}).String(), "murmur3 32")
}