checksum/hash/crc32koopman_test.go

58 lines
931 B
Go

package hash
import (
"github.com/tursom/checksum/assert"
"hash"
"hash/crc32"
"testing"
)
func TestCrc32Koopman_Finish(t *testing.T) {
type fields struct {
d hash.Hash
}
tests := []struct {
name string
fields fields
builder func(m *Crc32Koopman)
want []byte
}{
{
"nil",
fields{},
nil,
crc32.New(KoopmanTable).Sum(nil),
},
{
"hello",
fields{},
func(m *Crc32Koopman) {
m.Append([]byte("hello"))
},
crc32KoopmanSum([]byte("hello")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := &Crc32Koopman{
d: tt.fields.d,
}
if tt.builder != nil {
tt.builder(m)
}
assert.Equals(t, m.Finish(), tt.want)
})
}
}
func crc32KoopmanSum(b []byte) []byte {
h := crc32.New(KoopmanTable)
h.Write(b)
return h.Sum(nil)
}
func TestCrc32Koopman_String(t *testing.T) {
assert.Equals(t, (&Crc32Koopman{}).String(), "crc32koopman")
}