checksum/hash/fnv32a_test.go

58 lines
860 B
Go

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