Debian Codegraph @

ff/cmp_test.go

raw symbols SCIP
1 package ff
2
3 import "testing"
4
5 func Test_cmp(t *testing.T) {
6 type args struct {
7 a [4]uint64
8 b [4]uint64
9 }
10 tests := []struct {
11 name string
12 args args
13 want int
14 }{
15 {"1=1", args{[4]uint64{1, 0, 0, 0}, [4]uint64{1, 0, 0, 0}}, 0},
16 {"1<2", args{[4]uint64{1, 0, 0, 0}, [4]uint64{2, 0, 0, 0}}, -1},
17 {"2>1", args{[4]uint64{2, 0, 0, 0}, [4]uint64{1, 0, 0, 0}}, 1},
18 }
19 for _, tt := range tests {
20 t.Run(tt.name, func(t *testing.T) {
21 if got := cmp(tt.args.a, tt.args.b); got != tt.want {
22 t.Errorf("cmp() = %v, want %v", got, tt.want)
23 }
24 })
25 }
26 }
27
28 func Test_cmp_random(t *testing.T) {
29 for i := 0; i < 100; i++ {
30 x := randomElement(2 * i)
31 y := randomElement(2*i + 1)
32 A, B := ElementToBigInt(x), ElementToBigInt(y)
33 got := cmp(x, y)
34 want := A.Cmp(B)
35 if got != want {
36 t.Errorf("/%d add(%v,%v) = %v, want %v", i, x, y, got, want)
37 t.FailNow()
38 }
39 }
40 }
41
42 func Benchmark_cmp(b *testing.B) {
43 x := randomElement(1)
44 y := randomElement(2)
45 b.ResetTimer()
46 for i := 0; i < b.N; i++ {
47 cmp(x, y)
48 }
49 }
50
51 func Benchmark_cmp_BI(b *testing.B) {
52 x := ElementToBigInt(randomElement(1))
53 y := ElementToBigInt(randomElement(2))
54 b.ResetTimer()
55 for i := 0; i < b.N; i++ {
56 x.Cmp(y)
57 }
58 }