github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/util/math/exp_test.go (about)

     1  package math_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/filecoin-project/go-state-types/big"
     7  	"github.com/filecoin-project/specs-actors/v4/actors/util/math"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestExpBySquaring(t *testing.T) {
    12  	one := big.Lsh(big.NewInt(1), math.Precision128)
    13  	two := big.Lsh(big.NewInt(2), math.Precision128)
    14  	three := big.Lsh(big.NewInt(3), math.Precision128)
    15  	five := big.Lsh(big.NewInt(5), math.Precision128)
    16  	seven := big.Lsh(big.NewInt(7), math.Precision128)
    17  
    18  	assert.Equal(t, one, math.ExpBySquaring(three, int64(0)))
    19  	assert.Equal(t, one, math.ExpBySquaring(one, 1))
    20  	assert.Equal(t, three, math.ExpBySquaring(three, 1))
    21  
    22  	assert.Equal(t,
    23  		big.Lsh(big.NewInt(70368744177664), math.Precision128),
    24  		math.ExpBySquaring(two, 46),
    25  	)
    26  	assert.Equal(t,
    27  		big.Lsh(big.NewInt(3486784401), math.Precision128),
    28  		math.ExpBySquaring(three, 20),
    29  	)
    30  	assert.Equal(t,
    31  		big.Lsh(big.NewInt(1953125), math.Precision128),
    32  		math.ExpBySquaring(five, 9),
    33  	)
    34  	assert.Equal(t,
    35  		big.Lsh(big.NewInt(117649), math.Precision128),
    36  		math.ExpBySquaring(seven, 6),
    37  	)
    38  }