checksum/hash/murmur3_64_test.go

58 lines
909 B
Go

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