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