Debian Codegraph @

ff/add_test.go

raw symbols SCIP
1 package ff
2
3 import (
4 "math/big"
5 "testing"
6 )
7
8 func Test_add_random(t *testing.T) {
9 for i := 0; i < 100; i++ {
10 x := randomElement(2 * i)
11 y := randomElement(2*i + 1)
12 y[3] = y[3] & 0x7fffffffffffffff // clear last bit so garunteed it will fit in 256 bits
13 got := add(x, y)
14 want := BigIntToElement(new(big.Int).Add(ElementToBigInt(x), ElementToBigInt(y)))
15 if got != want {
16 t.Errorf("/%d add(%v,%v) = %v, want %v", i, x, y, got, want)
17 t.FailNow()
18 }
19 }
20 }
21
22 func Benchmark_add(b *testing.B) {
23 x := randomElement(1)
24 y := randomElement(2)
25 y[3] = y[3] & 0x7fffffffffffffff
26 b.ResetTimer()
27 for i := 0; i < b.N; i++ {
28 add(x, y)
29 }
30 }
31
32 func Benchmark_add_BI(b *testing.B) {
33 x := randomElement(1)
34 y := randomElement(2)
35 y[3] = y[3] & 0x7fffffffffffffff
36 A, B := ElementToBigInt(x), ElementToBigInt(y)
37 C := new(big.Int)
38 b.ResetTimer()
39 for i := 0; i < b.N; i++ {
40 C.Add(A, B)
41 }
42 }