| 1 | package ff |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func Test_normalize(t *testing.T) { |
| 9 | type args struct { |
| 10 | a Element |
| 11 | } |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | args args |
| 15 | want Element |
| 16 | }{ |
| 17 | {"1", args{Element{1, 0, 0, 0}}, Element{1, 0, 0, 0}}, |
| 18 | {"0", args{Element{0, 0, 0, 0}}, Element{0, 0, 0, 0}}, |
| 19 | {"p", args{p}, Element{0, 0, 0, 0}}, |
| 20 | {"2p", args{Element{0x8008206104082, 0, 0x4002081, 0x8000000000000000}}, Element{0, 0, 0, 0}}, |
| 21 | {"2p+1", args{Element{0x8008206104083, 0, 0x4002081, 0x8000000000000000}}, Element{1, 0, 0, 0}}, |
| 22 | } |
| 23 | for _, tt := range tests { |
| 24 | t.Run(tt.name, func(t *testing.T) { |
| 25 | if got := normalize(tt.args.a); !reflect.DeepEqual(got, tt.want) { |
| 26 | t.Errorf("normalize() = %v, want %v", got, tt.want) |
| 27 | } |
| 28 | }) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func Benchmark_normalize(b *testing.B) { |
| 33 | a := randomElement(1) |
| 34 | b.ResetTimer() |
| 35 | for i := 0; i < b.N; i++ { |
| 36 | normalize(a) |
| 37 | } |
| 38 | } |