Skip to content

Add encode & decode operations to base62 helper #10038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
update tests
  • Loading branch information
sgmiller committed Sep 25, 2020
commit 4d628da54eefbb243c6164ef5641e11477de0dbc
40 changes: 15 additions & 25 deletions sdk/helper/base62/base62_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package base62

import (
"bytes"
"crypto/rand"
"strings"
"testing"
)

Expand Down Expand Up @@ -31,9 +34,10 @@ func TestRandom(t *testing.T) {
}

func TestDecode(t *testing.T) {
str := "A fairly simple test"
str := strings.Repeat("x", 10000)

e := Encode([]byte(str))
b, err := DecodeString(e)
b, err := Decode(nil, e)

if err != nil {
t.Fail()
Expand All @@ -42,29 +46,15 @@ func TestDecode(t *testing.T) {
t.Fail()
}

// A slightly harder test
str,err = Random(200)
if err != nil {
t.Fail()
}
b, err = DecodeString(str)
if err != nil {
t.Fail()
}
e = Encode(b)
if e != str {
t.Fail()
}
}

func BenchmarkEncodeDecode(b *testing.B) {
str,_ := Random(200)
for i := 0; i<b.N; i++ {
o, _ := DecodeString(str)
e := Encode(o)
if e != str {
b.Fail()
break
input := make([]byte, 4)
for i := 0; i < 10000; i++ {
output := make([]byte, 4)
rand.Read(input)
str = Encode(input)
b, err = Decode(output, str)
if !bytes.Equal(b, input) {
//e = Encode(b)
t.Fail()
}
}
}