checksum/hash/fnv128a_test.go

58 lines
871 B
Go

package hash
import (
"github.com/tursom/checksum/assert"
"hash"
"hash/fnv"
"testing"
)
func TestFnv128a_Finish(t *testing.T) {
type fields struct {
d hash.Hash
}
tests := []struct {
name string
fields fields
builder func(m *Fnv128a)
want []byte
}{
{
"nil",
fields{},
nil,
fnv.New128a().Sum(nil),
},
{
"hello",
fields{},
func(m *Fnv128a) {
m.Append([]byte("hello"))
},
fnv128aSum([]byte("hello")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Fnv128a{
d: tt.fields.d,
}
if tt.builder != nil {
tt.builder(m)
}
assert.Equals(t, m.Finish(), tt.want)
})
}
}
func fnv128aSum(b []byte) []byte {
h := fnv.New128a()
_, _ = h.Write(b)
return h.Sum(nil)
}
func TestFnv128a_String(t *testing.T) {
assert.Equals(t, (&Fnv128a{}).String(), "fnv128a")
}