github.com/consensys/gnark-crypto@v0.14.0/ecc/bw6-756/fr/iop/expressions_test.go (about) 1 // Copyright 2020 Consensys Software Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Code generated by consensys/gnark-crypto DO NOT EDIT 16 17 package iop 18 19 import ( 20 "testing" 21 22 "github.com/consensys/gnark-crypto/ecc/bw6-756/fr" 23 ) 24 25 func TestEvaluate(t *testing.T) { 26 27 f := func(_ int, x ...fr.Element) fr.Element { 28 var a fr.Element 29 a.Add(&x[0], &x[1]).Add(&a, &x[2]) 30 return a 31 } 32 33 size := 64 34 u := make([]fr.Element, size) 35 v := make([]fr.Element, size) 36 w := make([]fr.Element, size) 37 for i := 0; i < size; i++ { 38 u[i].SetUint64(uint64(i)) 39 v[i].SetUint64(uint64(i + 1)) 40 w[i].SetUint64(uint64(i + 2)) 41 } 42 r := make([]fr.Element, size) 43 for i := 0; i < size; i++ { 44 r[i].SetUint64(uint64(3 * (i + 1))) 45 } 46 form := Form{Layout: Regular, Basis: Canonical} 47 wu := NewPolynomial(&u, form) 48 wv := NewPolynomial(&v, form) 49 ww := NewPolynomial(&w, form) 50 51 rr, err := Evaluate(f, nil, form, wu, wv, ww) 52 if err != nil { 53 t.Fatal(err) 54 } 55 56 wu.ToBitReverse() 57 rrb, err := Evaluate(f, nil, form, wu, wv, ww) 58 if err != nil { 59 t.Fatal(err) 60 } 61 62 wv.ToBitReverse() 63 ww.ToBitReverse() 64 rrc, err := Evaluate(f, nil, form, wu, wv, ww) 65 if err != nil { 66 t.Fatal(err) 67 } 68 69 // compare with the expected result 70 for i := 0; i < size; i++ { 71 if !rr.Coefficients()[i].Equal(&r[i]) { 72 t.Fatal("error evaluation") 73 } 74 if !rrb.Coefficients()[i].Equal(&r[i]) { 75 t.Fatal("error evaluation") 76 } 77 if !rrc.Coefficients()[i].Equal(&r[i]) { 78 t.Fatal("error evaluation") 79 } 80 81 } 82 }