-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgocx_test.go
59 lines (51 loc) · 1.4 KB
/
gocx_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
package cx
import (
"testing"
"testing/quick"
)
func TestS2b(t *testing.T) {
f := func(s string) bool {
b := S2b(s)
return string(b) == s // Check round-trip integrity
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}
func TestB2s(t *testing.T) {
f := func(b []byte) bool {
s := B2s(b)
return string(b) == s // Check round-trip integrity
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}
func BenchmarkS2b(b *testing.B) {
sampleString := "a sample string used for benchmarking the conversion from string to byte slice"
b.ResetTimer()
for i := 0; i < b.N; i++ {
S2b(sampleString)
}
}
func BenchmarkB2s(b *testing.B) {
sampleBytes := []byte("a sample byte slice used for benchmarking the conversion from byte slice to string")
b.ResetTimer()
for i := 0; i < b.N; i++ {
B2s(sampleBytes)
}
}
func BenchmarkString2Bytes(b *testing.B) {
sampleString := "a sample string used for benchmarking the conversion from string to byte slice"
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = []byte(sampleString)
}
}
func BenchmarkBytes2String(b *testing.B) {
sampleBytes := []byte("a sample byte slice used for benchmarking the conversion from byte slice to string")
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = string(sampleBytes)
}
}