checksum/hash/fnv128_test.go

58 lines
860 B
Go
Raw Normal View History

2023-08-01 16:27:27 +08:00
package hash
2023-08-01 15:32:05 +08:00
import (
"github.com/tursom/checksum/assert"
"hash"
"hash/fnv"
"testing"
)
func TestFnv128_Finish(t *testing.T) {
type fields struct {
d hash.Hash
}
tests := []struct {
name string
fields fields
builder func(m *Fnv128)
want []byte
}{
{
"nil",
fields{},
nil,
fnv.New128().Sum(nil),
},
{
"hello",
fields{},
func(m *Fnv128) {
m.Append([]byte("hello"))
},
fnv128Sum([]byte("hello")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Fnv128{
d: tt.fields.d,
}
if tt.builder != nil {
tt.builder(m)
}
assert.Equals(t, m.Finish(), tt.want)
})
}
}
func fnv128Sum(b []byte) []byte {
h := fnv.New128()
_, _ = h.Write(b)
return h.Sum(nil)
}
func TestFnv128_String(t *testing.T) {
assert.Equals(t, (&Fnv128{}).String(), "fnv128")
}