2023-08-01 16:27:27 +08:00
|
|
|
package hash
|
2023-08-01 15:32:05 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tursom/checksum/assert"
|
2023-08-01 15:49:57 +08:00
|
|
|
"github.com/twmb/murmur3"
|
2023-08-01 15:32:05 +08:00
|
|
|
"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")
|
|
|
|
}
|