Debian Codegraph @

ff/sub_test.go

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