github.com/Finschia/finschia-sdk@v0.48.1/types/uint_internal_test.go (about)

     1  package types
     2  
     3  import (
     4  	"math/big"
     5  	"math/rand"
     6  	"strconv"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/suite"
    10  )
    11  
    12  type uintInternalTestSuite struct {
    13  	suite.Suite
    14  }
    15  
    16  func TestUintInternalTestSuite(t *testing.T) {
    17  	suite.Run(t, new(uintInternalTestSuite))
    18  }
    19  
    20  func (s *uintInternalTestSuite) SetupSuite() {
    21  	s.T().Parallel()
    22  }
    23  
    24  func (s *uintInternalTestSuite) TestIdentUint() {
    25  	for d := 0; d < 1000; d++ {
    26  		n := rand.Uint64()
    27  		i := NewUint(n)
    28  
    29  		ifromstr := NewUintFromString(strconv.FormatUint(n, 10))
    30  
    31  		cases := []uint64{
    32  			i.Uint64(),
    33  			i.BigInt().Uint64(),
    34  			i.i.Uint64(),
    35  			ifromstr.Uint64(),
    36  			NewUintFromBigInt(new(big.Int).SetUint64(n)).Uint64(),
    37  		}
    38  
    39  		for tcnum, tc := range cases {
    40  			s.Require().Equal(n, tc, "Uint is modified during conversion. tc #%d", tcnum)
    41  		}
    42  	}
    43  }
    44  
    45  func (s *uintInternalTestSuite) TestUintSize() {
    46  	x := Uint{i: nil}
    47  	s.Require().Equal(1, x.Size())
    48  	x = NewUint(0)
    49  	s.Require().Equal(1, x.Size())
    50  	x = NewUint(10)
    51  	s.Require().Equal(2, x.Size())
    52  	x = NewUint(100)
    53  	s.Require().Equal(3, x.Size())
    54  }