Skip to content

Commit

Permalink
test: added non regression test for api.Select bool cond
Browse files Browse the repository at this point in the history
  • Loading branch information
gbotrel committed Aug 13, 2024
1 parent ea53f37 commit 0c35f15
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/regression_tests/issue1246/issue1246_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package issue1246_test

import (
"testing"

"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/test"
)

// Circuit definition
// here we aim to catch the case where the API doesn't enforce the condition to be a boolean
type notBoolCond struct {
Condition, Y1, Y2 frontend.Variable
}

func (circuit *notBoolCond) Define(api frontend.API) error {
d := api.Select(circuit.Condition, circuit.Y1, circuit.Y2)

// per api definition, d should hold either Y1 or Y2.
// we have y1 = 2, y2 = 4, condition = 2 (non boolean)
// r = condition(y1-y2) + y2
api.AssertIsEqual(d, 0)

return nil
}

func TestSelectConditionNonBool(t *testing.T) {
assert := test.NewAssert(t)

assert.CheckCircuit(&notBoolCond{},
test.WithInvalidAssignment(&notBoolCond{
Condition: 2,
Y1: 2,
Y2: 4,
}),
)
}

0 comments on commit 0c35f15

Please sign in to comment.