github.com/consensys/gnark@v0.11.0/test/api_assertions_test.go (about)

     1  package test
     2  
     3  import (
     4  	"github.com/consensys/gnark/frontend"
     5  	"math/rand"
     6  	"testing"
     7  )
     8  
     9  func TestIsCrumb(t *testing.T) {
    10  	c := []frontend.Variable{0, 1, 2, 3}
    11  	assert := NewAssert(t)
    12  	assert.SolvingSucceeded(&isCrumbCircuit{C: make([]frontend.Variable, len(c))}, &isCrumbCircuit{C: c})
    13  	for n := 0; n < 20; n++ {
    14  		x := rand.Intn(65531) + 4 //#nosec G404 weak rng OK for test
    15  		assert.SolvingFailed(&isCrumbCircuit{C: []frontend.Variable{nil}}, &isCrumbCircuit{C: []frontend.Variable{x}})
    16  	}
    17  }
    18  
    19  type isCrumbCircuit struct {
    20  	C []frontend.Variable
    21  }
    22  
    23  func (circuit *isCrumbCircuit) Define(api frontend.API) error {
    24  	for _, x := range circuit.C {
    25  		api.AssertIsCrumb(x)
    26  	}
    27  	return nil
    28  }