-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadbytes_test.go
More file actions
71 lines (64 loc) · 1.19 KB
/
loadbytes_test.go
File metadata and controls
71 lines (64 loc) · 1.19 KB
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
package fmt
import "testing"
func TestLoadBytesInt64(t *testing.T) {
c := GetConv()
defer c.PutConv()
c.LoadBytes([]byte("42"))
v, err := c.Int64()
if err != nil {
t.Fatal(err)
}
if v != 42 {
t.Errorf("expected 42, got %d", v)
}
}
func TestLoadBytesFloat64(t *testing.T) {
c := GetConv()
defer c.PutConv()
c.LoadBytes([]byte("9.5"))
v, err := c.Float64()
if err != nil {
t.Fatal(err)
}
if v != 9.5 {
t.Errorf("expected 9.5, got %f", v)
}
}
func TestLoadBytesNegative(t *testing.T) {
c := GetConv()
defer c.PutConv()
c.LoadBytes([]byte("-100"))
v, _ := c.Int64()
if v != -100 {
t.Errorf("expected -100, got %d", v)
}
}
func TestLoadBytesScientific(t *testing.T) {
c := GetConv()
defer c.PutConv()
c.LoadBytes([]byte("1.5e2"))
v, _ := c.Float64()
if v != 150 {
t.Errorf("expected 150, got %f", v)
}
}
func BenchmarkLoadBytesInt64(b *testing.B) {
data := []byte("12345")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
c := GetConv()
c.LoadBytes(data)
c.Int64()
c.PutConv()
}
}
func BenchmarkLoadBytesFloat64(b *testing.B) {
data := []byte("3.14159")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
c := GetConv()
c.LoadBytes(data)
c.Float64()
c.PutConv()
}
}