-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpow10_test.go
55 lines (51 loc) · 868 Bytes
/
pow10_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
package coin
import (
"math"
"math/big"
"strconv"
"strings"
"testing"
"github.com/mkobetic/coin/assert"
)
func Test_Log10(t *testing.T) {
for i, fix := range []struct {
in int64
out int
}{
{-5, 0},
{0, 0},
{9, 0},
{10, 1},
{99, 1},
{100, 2},
{19999, 4},
{1000000, 6},
{math.MaxInt64, 18},
} {
l10 := log10(fix.in)
assert.Equal(t, l10, fix.out, "%d. not equal", i)
}
}
func Test_BigPow10(t *testing.T) {
for i, fix := range []struct {
in string
out int
}{
{"-555", 2},
{"-5", 0},
{"0", 0},
{"9", 0},
{"10", 1},
{"99", 1},
{"100", 2},
{"19999", 4},
{"1000000", 6},
{strconv.FormatInt(math.MaxInt64, 10), 18},
{strings.Repeat("11", 20), 39},
} {
bi, ok := new(big.Int).SetString(fix.in, 10)
assert.Equal(t, ok, true)
l10 := bigLog10(bi)
assert.Equal(t, l10, fix.out, "%d. not equal", i)
}
}