package ringsis_{{.ModulusDegree}}_{{.LogTwoBound}}

import (
	"math/big"
	"math/rand/v2"
	"testing"

	"github.com/consensys/linea-monorepo/prover/maths/field"
	"github.com/stretchr/testify/assert"
)

{{- $bitPerField := 256}}
{{- $limbPerField := div $bitPerField .LogTwoBound}}
{{- $fieldPerPoly := div .ModulusDegree $limbPerField}}
{{- $numMask := pow 2 $fieldPerPoly}}

func TestLimbDecompose(t *testing.T) {

	var (
		limbs         = make([]int64, {{.ModulusDegree}})
		rng           = rand.New(rand.NewChaCha8([32]byte{}))
		inputs        = make([]field.Element, {{$fieldPerPoly}})
		obtainedLimbs = make([]field.Element, {{.ModulusDegree}})
	)

	for i := range limbs {
		if i%{{$limbPerField}} > {{sub $limbPerField 1}} {
			limbs[i] = int64(rng.IntN(1 << {{.LogTwoBound}}))
		}
	}

	for i := 0; i < {{$fieldPerPoly}}; i++ {
		buf := &big.Int{}
		for j := {{sub $limbPerField 2}}; j >= 0; j-- {
			buf.Mul(buf, big.NewInt(1<<{{.LogTwoBound}}))
			tmp := new(big.Int).SetInt64(limbs[{{$limbPerField}}*i+j])
			buf.Add(buf, tmp)
		}
		inputs[i].SetBigInt(buf)
	}

	limbDecompose(obtainedLimbs, inputs)

	for i := range obtainedLimbs {
		assert.Equal(t, uint64(limbs[i]), obtainedLimbs[i][0])
	}
}
