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