8
func TestCommas(t *testing.T) {
11
{"10", Comma(10), "10"},
12
{"100", Comma(100), "100"},
13
{"1,000", Comma(1000), "1,000"},
14
{"10,000", Comma(10000), "10,000"},
15
{"100,000", Comma(100000), "100,000"},
16
{"10,000,000", Comma(10000000), "10,000,000"},
17
{"10,100,000", Comma(10100000), "10,100,000"},
18
{"10,010,000", Comma(10010000), "10,010,000"},
19
{"10,001,000", Comma(10001000), "10,001,000"},
20
{"123,456,789", Comma(123456789), "123,456,789"},
21
{"maxint", Comma(9.223372e+18), "9,223,372,000,000,000,000"},
22
{"minint", Comma(-9.223372e+18), "-9,223,372,000,000,000,000"},
23
{"-123,456,789", Comma(-123456789), "-123,456,789"},
24
{"-10,100,000", Comma(-10100000), "-10,100,000"},
25
{"-10,010,000", Comma(-10010000), "-10,010,000"},
26
{"-10,001,000", Comma(-10001000), "-10,001,000"},
27
{"-10,000,000", Comma(-10000000), "-10,000,000"},
28
{"-100,000", Comma(-100000), "-100,000"},
29
{"-10,000", Comma(-10000), "-10,000"},
30
{"-1,000", Comma(-1000), "-1,000"},
31
{"-100", Comma(-100), "-100"},
32
{"-10", Comma(-10), "-10"},
36
func BenchmarkCommas(b *testing.B) {
37
for i := 0; i < b.N; i++ {
42
func BenchmarkBigCommas(b *testing.B) {
43
for i := 0; i < b.N; i++ {
44
BigComma(big.NewInt(1234567890))
48
func bigComma(i int64) string {
49
return BigComma(big.NewInt(i))
52
func TestBigCommas(t *testing.T) {
54
{"0", bigComma(0), "0"},
55
{"10", bigComma(10), "10"},
56
{"100", bigComma(100), "100"},
57
{"1,000", bigComma(1000), "1,000"},
58
{"10,000", bigComma(10000), "10,000"},
59
{"100,000", bigComma(100000), "100,000"},
60
{"10,000,000", bigComma(10000000), "10,000,000"},
61
{"10,100,000", bigComma(10100000), "10,100,000"},
62
{"10,010,000", bigComma(10010000), "10,010,000"},
63
{"10,001,000", bigComma(10001000), "10,001,000"},
64
{"123,456,789", bigComma(123456789), "123,456,789"},
65
{"maxint", bigComma(9.223372e+18), "9,223,372,000,000,000,000"},
66
{"minint", bigComma(-9.223372e+18), "-9,223,372,000,000,000,000"},
67
{"-123,456,789", bigComma(-123456789), "-123,456,789"},
68
{"-10,100,000", bigComma(-10100000), "-10,100,000"},
69
{"-10,010,000", bigComma(-10010000), "-10,010,000"},
70
{"-10,001,000", bigComma(-10001000), "-10,001,000"},
71
{"-10,000,000", bigComma(-10000000), "-10,000,000"},
72
{"-100,000", bigComma(-100000), "-100,000"},
73
{"-10,000", bigComma(-10000), "-10,000"},
74
{"-1,000", bigComma(-1000), "-1,000"},
75
{"-100", bigComma(-100), "-100"},
76
{"-10", bigComma(-10), "-10"},
80
func TestVeryBigCommas(t *testing.T) {
81
tests := []struct{ in, exp string }{
83
"84889279597249724975972597249849757294578485",
84
"84,889,279,597,249,724,975,972,597,249,849,757,294,578,485",
87
"-84889279597249724975972597249849757294578485",
88
"-84,889,279,597,249,724,975,972,597,249,849,757,294,578,485",
91
for _, test := range tests {
92
n, _ := (&big.Int{}).SetString(test.in, 10)
95
t.Errorf("Expected %q, got %q", test.exp, got)