github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/math/polynomial_test.go (about) 1 package math 2 3 import ( 4 "math/big" 5 "testing" 6 7 "gotest.tools/assert" 8 ) 9 10 func intArray2BigArray(coefficients []int) []*big.Int { 11 result := make([]*big.Int, len(coefficients)) 12 for i, c := range coefficients { 13 result[i] = big.NewInt(int64(c)) 14 } 15 return result 16 } 17 18 func TestPolynomial(t *testing.T) { 19 20 // euler formula to calculate Partition(5) 21 p1 := NewPolynomial(intArray2BigArray([]int{1, 1, 1, 1, 1, 1})) 22 p2 := NewPolynomial(intArray2BigArray([]int{1, 0, 1, 0, 1})) 23 p3 := NewPolynomial(intArray2BigArray([]int{1, 0, 0, 1})) 24 p4 := NewPolynomial(intArray2BigArray([]int{1, 0, 0, 0, 1})) 25 p5 := NewPolynomial(intArray2BigArray([]int{1, 0, 0, 0, 0, 1})) 26 27 p := p1.Mul(p2).Mul(p3).Mul(p4).Mul(p5) 28 assert.Equal(t, p.coefficients[5].Uint64(), uint64(7)) 29 t.Log(p) 30 }