You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
924 B

  1. // code originally taken from https://github.com/arnaucube/go-snark (https://github.com/arnaucube/go-snark/blob/master/fields/fq.go), pasted here to ensure compatibility among future changes
  2. package field
  3. import (
  4. "math/big"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func iToBig(a int) *big.Int {
  9. return big.NewInt(int64(a))
  10. }
  11. func TestFq1(t *testing.T) {
  12. fq1 := NewFq(iToBig(7))
  13. res := fq1.Add(iToBig(4), iToBig(4))
  14. assert.Equal(t, iToBig(1), fq1.Affine(res))
  15. res = fq1.Double(iToBig(5))
  16. assert.Equal(t, iToBig(3), fq1.Affine(res))
  17. res = fq1.Sub(iToBig(5), iToBig(7))
  18. assert.Equal(t, iToBig(5), fq1.Affine(res))
  19. res = fq1.Neg(iToBig(5))
  20. assert.Equal(t, iToBig(2), fq1.Affine(res))
  21. res = fq1.Mul(iToBig(5), iToBig(11))
  22. assert.Equal(t, iToBig(6), fq1.Affine(res))
  23. res = fq1.Inverse(iToBig(4))
  24. assert.Equal(t, iToBig(2), res)
  25. res = fq1.Square(iToBig(5))
  26. assert.Equal(t, iToBig(4), res)
  27. }