summaryrefslogtreecommitdiff
path: root/libgo/go/strconv/itoa_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/strconv/itoa_test.go')
-rw-r--r--libgo/go/strconv/itoa_test.go124
1 files changed, 55 insertions, 69 deletions
diff --git a/libgo/go/strconv/itoa_test.go b/libgo/go/strconv/itoa_test.go
index 8514b21e47c..e0213ae9afe 100644
--- a/libgo/go/strconv/itoa_test.go
+++ b/libgo/go/strconv/itoa_test.go
@@ -11,7 +11,7 @@ import (
type itob64Test struct {
in int64
- base uint
+ base int
out string
}
@@ -60,73 +60,43 @@ var itob64tests = []itob64Test{
func TestItoa(t *testing.T) {
for _, test := range itob64tests {
- s := Itob64(test.in, test.base)
+ s := FormatInt(test.in, test.base)
if s != test.out {
- t.Errorf("Itob64(%v, %v) = %v want %v",
+ t.Errorf("FormatInt(%v, %v) = %v want %v",
test.in, test.base, s, test.out)
}
-
- if test.in >= 0 {
- s := Uitob64(uint64(test.in), test.base)
- if s != test.out {
- t.Errorf("Uitob64(%v, %v) = %v want %v",
- test.in, test.base, s, test.out)
- }
+ x := AppendInt([]byte("abc"), test.in, test.base)
+ if string(x) != "abc"+test.out {
+ t.Errorf("AppendInt(%q, %v, %v) = %q want %v",
+ "abc", test.in, test.base, x, test.out)
}
- if int64(int(test.in)) == test.in {
- s := Itob(int(test.in), test.base)
+ if test.in >= 0 {
+ s := FormatUint(uint64(test.in), test.base)
if s != test.out {
- t.Errorf("Itob(%v, %v) = %v want %v",
+ t.Errorf("FormatUint(%v, %v) = %v want %v",
test.in, test.base, s, test.out)
}
-
- if test.in >= 0 {
- s := Uitob(uint(test.in), test.base)
- if s != test.out {
- t.Errorf("Uitob(%v, %v) = %v want %v",
- test.in, test.base, s, test.out)
- }
+ x := AppendUint(nil, uint64(test.in), test.base)
+ if string(x) != test.out {
+ t.Errorf("AppendUint(%q, %v, %v) = %q want %v",
+ "abc", uint64(test.in), test.base, x, test.out)
}
}
- if test.base == 10 {
- s := Itoa64(test.in)
+ if test.base == 10 && int64(int(test.in)) == test.in {
+ s := Itoa(int(test.in))
if s != test.out {
- t.Errorf("Itoa64(%v) = %v want %v",
+ t.Errorf("Itoa(%v) = %v want %v",
test.in, s, test.out)
}
-
- if test.in >= 0 {
- s := Uitob64(uint64(test.in), test.base)
- if s != test.out {
- t.Errorf("Uitob64(%v, %v) = %v want %v",
- test.in, test.base, s, test.out)
- }
- }
-
- if int64(int(test.in)) == test.in {
- s := Itoa(int(test.in))
- if s != test.out {
- t.Errorf("Itoa(%v) = %v want %v",
- test.in, s, test.out)
- }
-
- if test.in >= 0 {
- s := Uitoa(uint(test.in))
- if s != test.out {
- t.Errorf("Uitoa(%v) = %v want %v",
- test.in, s, test.out)
- }
- }
- }
}
}
}
type uitob64Test struct {
in uint64
- base uint
+ base int
out string
}
@@ -141,34 +111,50 @@ var uitob64tests = []uitob64Test{
func TestUitoa(t *testing.T) {
for _, test := range uitob64tests {
- s := Uitob64(test.in, test.base)
+ s := FormatUint(test.in, test.base)
if s != test.out {
- t.Errorf("Uitob64(%v, %v) = %v want %v",
+ t.Errorf("FormatUint(%v, %v) = %v want %v",
test.in, test.base, s, test.out)
}
+ x := AppendUint([]byte("abc"), test.in, test.base)
+ if string(x) != "abc"+test.out {
+ t.Errorf("AppendUint(%q, %v, %v) = %q want %v",
+ "abc", test.in, test.base, x, test.out)
+ }
- if uint64(uint(test.in)) == test.in {
- s := Uitob(uint(test.in), test.base)
- if s != test.out {
- t.Errorf("Uitob(%v, %v) = %v want %v",
- test.in, test.base, s, test.out)
- }
+ }
+}
+
+func BenchmarkFormatInt(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ for _, test := range itob64tests {
+ FormatInt(test.in, test.base)
}
+ }
+}
- if test.base == 10 {
- s := Uitoa64(test.in)
- if s != test.out {
- t.Errorf("Uitoa64(%v) = %v want %v",
- test.in, s, test.out)
- }
+func BenchmarkAppendInt(b *testing.B) {
+ dst := make([]byte, 0, 30)
+ for i := 0; i < b.N; i++ {
+ for _, test := range itob64tests {
+ AppendInt(dst, test.in, test.base)
+ }
+ }
+}
- if uint64(uint(test.in)) == test.in {
- s := Uitoa(uint(test.in))
- if s != test.out {
- t.Errorf("Uitoa(%v) = %v want %v",
- test.in, s, test.out)
- }
- }
+func BenchmarkFormatUint(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ for _, test := range uitob64tests {
+ FormatUint(test.in, test.base)
+ }
+ }
+}
+
+func BenchmarkAppendUint(b *testing.B) {
+ dst := make([]byte, 0, 30)
+ for i := 0; i < b.N; i++ {
+ for _, test := range uitob64tests {
+ AppendUint(dst, test.in, test.base)
}
}
}