File: cmp_test.go

package info (click to toggle)
golang-github-tscholl2-siec 0.0~git20210707.9bdfc48-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 360 kB
  • sloc: makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package ff

import "testing"

func Test_cmp(t *testing.T) {
	type args struct {
		a [4]uint64
		b [4]uint64
	}
	tests := []struct {
		name string
		args args
		want int
	}{
		{"1=1", args{[4]uint64{1, 0, 0, 0}, [4]uint64{1, 0, 0, 0}}, 0},
		{"1<2", args{[4]uint64{1, 0, 0, 0}, [4]uint64{2, 0, 0, 0}}, -1},
		{"2>1", args{[4]uint64{2, 0, 0, 0}, [4]uint64{1, 0, 0, 0}}, 1},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := cmp(tt.args.a, tt.args.b); got != tt.want {
				t.Errorf("cmp() = %v, want %v", got, tt.want)
			}
		})
	}
}

func Test_cmp_random(t *testing.T) {
	for i := 0; i < 100; i++ {
		x := randomElement(2 * i)
		y := randomElement(2*i + 1)
		A, B := ElementToBigInt(x), ElementToBigInt(y)
		got := cmp(x, y)
		want := A.Cmp(B)
		if got != want {
			t.Errorf("/%d add(%v,%v) = %v, want %v", i, x, y, got, want)
			t.FailNow()
		}
	}
}

func Benchmark_cmp(b *testing.B) {
	x := randomElement(1)
	y := randomElement(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		cmp(x, y)
	}
}

func Benchmark_cmp_BI(b *testing.B) {
	x := ElementToBigInt(randomElement(1))
	y := ElementToBigInt(randomElement(2))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		x.Cmp(y)
	}
}