github.com/consensys/gnark-crypto@v0.14.0/ecc/bw6-756/internal/fptower/generators_test.go (about)

     1  package fptower
     2  
     3  import (
     4  	"github.com/consensys/gnark-crypto/ecc/bw6-756/fp"
     5  	"github.com/leanovate/gopter"
     6  )
     7  
     8  // TODO all gopter.Gen are incorrect, use same model as goff
     9  
    10  // GenFp generates an Fp element
    11  func GenFp() gopter.Gen {
    12  	return func(genParams *gopter.GenParameters) *gopter.GenResult {
    13  		var elmt fp.Element
    14  
    15  		if _, err := elmt.SetRandom(); err != nil {
    16  			panic(err)
    17  		}
    18  		genResult := gopter.NewGenResult(elmt, gopter.NoShrinker)
    19  		return genResult
    20  	}
    21  }
    22  
    23  // GenE3 generates an E3 elmt
    24  func GenE3() gopter.Gen {
    25  	return gopter.CombineGens(
    26  		GenFp(),
    27  		GenFp(),
    28  		GenFp(),
    29  	).Map(func(values []interface{}) *E3 {
    30  		return &E3{A0: values[0].(fp.Element), A1: values[1].(fp.Element), A2: values[2].(fp.Element)}
    31  	})
    32  }
    33  
    34  // E6 generates an E6 elmt
    35  func GenE6() gopter.Gen {
    36  	return gopter.CombineGens(
    37  		GenE3(),
    38  		GenE3(),
    39  	).Map(func(values []interface{}) *E6 {
    40  		return &E6{B0: *values[0].(*E3), B1: *values[1].(*E3)}
    41  	})
    42  }