-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder_test.go
43 lines (36 loc) · 906 Bytes
/
encoder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package base64encoding
import (
"math"
"testing"
)
func TestNewCustom_PairwiseDistinction(t *testing.T) {
_, err := NewCustom(EasilyReadableCodeSet)
if err != nil {
t.Error(err)
}
// Easily readable code set with 2 runes alike
// | |
// v v
faulty := "*)23456789abcdefghi_klmnopqrstuvwxyzABCDEFGH+JKLMNOPQRSTkVWXYZ-$"
_, err = NewCustom(faulty)
if err != ErrNotDistinct {
t.Error(err)
}
}
func TestEncoder64_Num(t *testing.T) {
num := uint64(math.MaxUint64)
enc := New()
encoded := enc.EncodeNum(num)
actual, err := enc.DecodeNum(encoded)
if err != nil {
t.Error(err)
}
if actual != num {
t.Errorf("unequal: want: %d, got: %d", num, actual)
}
}
func BenchmarkNewCustom(b *testing.B) {
for i := 0; i < b.N; i++ {
NewCustom(StandardCodeSet)
}
}