-
Notifications
You must be signed in to change notification settings - Fork 63
/
scan_test.go
76 lines (64 loc) · 1.2 KB
/
scan_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package decimal
import (
"math/rand"
"strconv"
"testing"
)
func randString() string {
const chars = "0123456789"
n := rand.Intn(5000)
if n == 0 {
n = 16
}
p := make([]byte, n)
for i := range p {
p[i] = chars[rand.Intn(len(chars))]
}
switch rand.Intn(3) {
case 0:
p = append(p, 'e', '+')
p = strconv.AppendInt(p, int64(rand.Intn(350)), 10)
case 1:
p = append(p, 'e', '-')
p = strconv.AppendInt(p, int64(rand.Intn(350)), 10)
case 2:
if lp := len(p); lp > 0 {
p[rand.Intn(lp)] = '.'
}
}
return string(p)
}
var benchInput = func() (a [4096]struct {
b Big
s string
}) {
for i := range a {
a[i].s = randString()
}
return a
}()
var globOk bool
func BenchmarkBig_SetString(b *testing.B) {
var ok bool
for i := 0; i < b.N; i++ {
m := &benchInput[i%len(benchInput)]
_, ok = m.b.SetString(m.s)
}
globOk = ok
}
func TestUnmarshalTextTwice(t *testing.T) {
x := &Big{}
x.UnmarshalText([]byte(`1`))
x.UnmarshalText([]byte(`2`))
if x.String() != "2" {
t.Errorf("wanted: %q, got %q", "2", x.String())
}
}
func TestSetStringTwice(t *testing.T) {
x := &Big{}
x.SetString("1")
x.SetString("2")
if x.String() != "2" {
t.Errorf("wanted: %q, got %q", "2", x.String())
}
}