Skip to content

Commit

Permalink
Fix[hash]: Fix benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Nov 14, 2023
1 parent 22bad87 commit 4e59e82
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@ const (

var kayosByteSlice = []byte{107, 97, 121, 111, 115, 10}

var (
ogsha1, _ = base64.StdEncoding.DecodeString(kayosSHA1)
ogsha256, _ = base64.StdEncoding.DecodeString(kayosSHA256)
ogsha512, _ = base64.StdEncoding.DecodeString(kayosSHA512)
ogmd5, _ = base64.StdEncoding.DecodeString(kayosMD5)
ogBlake2b, _ = base64.StdEncoding.DecodeString(kayosBlake2b)
ogCRC32, _ = base64.StdEncoding.DecodeString(kayosCRC32)
valids = map[Type][]byte{
TypeSHA1: ogsha1,
TypeSHA256: ogsha256,
TypeSHA512: ogsha512,
TypeMD5: ogmd5,
TypeCRC32: ogCRC32,
TypeBlake2b: ogBlake2b,
}
)

func TestSum(t *testing.T) {
t.Parallel()
if Sum(TypeNull, []byte("yeet")) != nil {
t.Fatal("Sum(TypeNull, []byte(\"yeet\")) should have returned nil")
}

var (
ogsha1, _ = base64.StdEncoding.DecodeString(kayosSHA1)
ogsha256, _ = base64.StdEncoding.DecodeString(kayosSHA256)
ogsha512, _ = base64.StdEncoding.DecodeString(kayosSHA512)
ogmd5, _ = base64.StdEncoding.DecodeString(kayosMD5)
ogBlake2b, _ = base64.StdEncoding.DecodeString(kayosBlake2b)
ogCRC32, _ = base64.StdEncoding.DecodeString(kayosCRC32)
valids = map[Type][]byte{
TypeSHA1: ogsha1,
TypeSHA256: ogsha256,
TypeSHA512: ogsha512,
TypeMD5: ogmd5,
TypeCRC32: ogCRC32,
TypeBlake2b: ogBlake2b,
}
)
for k, v := range valids {
typeToTest := k
valueToTest := v
Expand Down Expand Up @@ -99,7 +100,7 @@ func TestSum(t *testing.T) {
var benchData = []byte(entropy.RandStrWithUpper(5000))

func BenchmarkSum(b *testing.B) {
for _, sumType := range []Type{TypeSHA1, TypeSHA256, TypeSHA512, TypeBlake2b, TypeMD5} {
for sumType := range valids {
b.Run(sumType.String(), func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
Expand Down

0 comments on commit 4e59e82

Please sign in to comment.