forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuint_internal_test.go
54 lines (44 loc) · 1.01 KB
/
uint_internal_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
package math
import (
"math/big"
"math/rand"
"strconv"
"testing"
"github.com/stretchr/testify/suite"
)
type uintInternalTestSuite struct {
suite.Suite
}
func TestUintInternalTestSuite(t *testing.T) {
suite.Run(t, new(uintInternalTestSuite))
}
func (s *uintInternalTestSuite) SetupSuite() {
s.T().Parallel()
}
func (s *uintInternalTestSuite) TestIdentUint() {
for d := 0; d < 1000; d++ {
n := rand.Uint64()
i := NewUint(n)
ifromstr := NewUintFromString(strconv.FormatUint(n, 10))
cases := []uint64{
i.Uint64(),
i.BigInt().Uint64(),
i.i.Uint64(),
ifromstr.Uint64(),
NewUintFromBigInt(new(big.Int).SetUint64(n)).Uint64(),
}
for tcnum, tc := range cases {
s.Require().Equal(n, tc, "Uint is modified during conversion. tc #%d", tcnum)
}
}
}
func (s *uintInternalTestSuite) TestUintSize() {
x := Uint{i: nil}
s.Require().Equal(1, x.Size())
x = NewUint(0)
s.Require().Equal(1, x.Size())
x = NewUint(10)
s.Require().Equal(2, x.Size())
x = NewUint(100)
s.Require().Equal(3, x.Size())
}