58 lines
849 B
Go
58 lines
849 B
Go
package hash
|
|
|
|
import (
|
|
"github.com/tursom/checksum/assert"
|
|
"hash"
|
|
"hash/fnv"
|
|
"testing"
|
|
)
|
|
|
|
func TestFnv32_Finish(t *testing.T) {
|
|
type fields struct {
|
|
d hash.Hash
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
builder func(m *Fnv32)
|
|
want []byte
|
|
}{
|
|
{
|
|
"nil",
|
|
fields{},
|
|
nil,
|
|
fnv.New32().Sum(nil),
|
|
},
|
|
{
|
|
"hello",
|
|
fields{},
|
|
func(m *Fnv32) {
|
|
m.Append([]byte("hello"))
|
|
},
|
|
fnv32Sum([]byte("hello")),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
m := &Fnv32{
|
|
d: tt.fields.d,
|
|
}
|
|
if tt.builder != nil {
|
|
tt.builder(m)
|
|
}
|
|
|
|
assert.Equals(t, m.Finish(), tt.want)
|
|
})
|
|
}
|
|
}
|
|
|
|
func fnv32Sum(b []byte) []byte {
|
|
h := fnv.New32()
|
|
_, _ = h.Write(b)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func TestFnv32_String(t *testing.T) {
|
|
assert.Equals(t, (&Fnv32{}).String(), "fnv32")
|
|
}
|