58 lines
898 B
Go
58 lines
898 B
Go
package hash
|
|
|
|
import (
|
|
"github.com/tursom/checksum/assert"
|
|
"hash"
|
|
"hash/crc64"
|
|
"testing"
|
|
)
|
|
|
|
func TestCrc64Ecma_Finish(t *testing.T) {
|
|
type fields struct {
|
|
d hash.Hash
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
builder func(m *Crc64Ecma)
|
|
want []byte
|
|
}{
|
|
{
|
|
"nil",
|
|
fields{},
|
|
nil,
|
|
crc64.New(ECMATable).Sum(nil),
|
|
},
|
|
{
|
|
"hello",
|
|
fields{},
|
|
func(m *Crc64Ecma) {
|
|
m.Append([]byte("hello"))
|
|
},
|
|
crc64EcmaSum([]byte("hello")),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
m := &Crc64Ecma{
|
|
d: tt.fields.d,
|
|
}
|
|
if tt.builder != nil {
|
|
tt.builder(m)
|
|
}
|
|
|
|
assert.Equals(t, m.Finish(), tt.want)
|
|
})
|
|
}
|
|
}
|
|
|
|
func crc64EcmaSum(b []byte) []byte {
|
|
h := crc64.New(ECMATable)
|
|
h.Write(b)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
func TestCrc64Ecma_String(t *testing.T) {
|
|
assert.Equals(t, (&Crc64Ecma{}).String(), "crc64ecma")
|
|
}
|