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