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

     1  package fptower
     2  
     3  import (
     4  	"github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
     5  	"github.com/leanovate/gopter"
     6  )
     7  
     8  // ------------------------------------------------------------
     9  // Tower generators
    10  
    11  // GenFp generates an Fp element
    12  func GenFp() gopter.Gen {
    13  	return func(genParams *gopter.GenParameters) *gopter.GenResult {
    14  		var elmt fp.Element
    15  
    16  		if _, err := elmt.SetRandom(); err != nil {
    17  			panic(err)
    18  		}
    19  		genResult := gopter.NewGenResult(elmt, gopter.NoShrinker)
    20  		return genResult
    21  	}
    22  }
    23  
    24  // GenE2 generates an E2 elmt
    25  func GenE2() gopter.Gen {
    26  	return gopter.CombineGens(
    27  		GenFp(),
    28  		GenFp(),
    29  	).Map(func(values []interface{}) *E2 {
    30  		return &E2{A0: values[0].(fp.Element), A1: values[1].(fp.Element)}
    31  	})
    32  }
    33  
    34  // GenE6 generates an E6 elmt
    35  func GenE6() gopter.Gen {
    36  	return gopter.CombineGens(
    37  		GenE2(),
    38  		GenE2(),
    39  		GenE2(),
    40  	).Map(func(values []interface{}) *E6 {
    41  		return &E6{B0: *values[0].(*E2), B1: *values[1].(*E2), B2: *values[2].(*E2)}
    42  	})
    43  }
    44  
    45  // GenE12 generates an E6 elmt
    46  func GenE12() gopter.Gen {
    47  	return gopter.CombineGens(
    48  		GenE6(),
    49  		GenE6(),
    50  	).Map(func(values []interface{}) *E12 {
    51  		return &E12{C0: *values[0].(*E6), C1: *values[1].(*E6)}
    52  	})
    53  }