2019-06-21 14:40:48 +00:00
|
|
|
package gf127
|
|
|
|
|
2019-06-24 07:56:15 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2019-06-21 14:40:48 +00:00
|
|
|
|
|
|
|
var testCasesSplit = []struct {
|
|
|
|
num *GF127x2
|
|
|
|
h1 *GF127
|
|
|
|
h2 *GF127
|
|
|
|
}{
|
2019-10-10 08:04:15 +00:00
|
|
|
{&GF127x2{GF127{123, 31}, GF127{141, 9}}, &GF127{123, 31}, &GF127{141, 9}},
|
|
|
|
{&GF127x2{GF127{maxUint64, 0}, GF127{0, maxUint64}}, &GF127{maxUint64, 0}, &GF127{0, maxUint64}},
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSplit(t *testing.T) {
|
|
|
|
for _, tc := range testCasesSplit {
|
|
|
|
a, b := Split(tc.num)
|
2019-06-24 07:56:15 +00:00
|
|
|
require.Equal(t, tc.h1, a)
|
|
|
|
require.Equal(t, tc.h2, b)
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCombineTo(t *testing.T) {
|
|
|
|
c := new(GF127x2)
|
|
|
|
for _, tc := range testCasesSplit {
|
|
|
|
CombineTo(tc.h1, tc.h2, c)
|
2019-06-24 07:56:15 +00:00
|
|
|
require.Equal(t, tc.num, c)
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testCasesMul10x2 = [][2]*GF127x2{
|
2019-10-10 08:04:15 +00:00
|
|
|
{
|
|
|
|
&GF127x2{GF127{123, 0}, GF127{123, 0}},
|
|
|
|
&GF127x2{GF127{246, 0}, GF127{246, 0}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&GF127x2{GF127{maxUint64, 2}, GF127{0, 1}},
|
|
|
|
&GF127x2{GF127{maxUint64 - 1, 5}, GF127{0, 2}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&GF127x2{GF127{0, maxUint64 >> 1}, GF127{maxUint64, 2}},
|
|
|
|
&GF127x2{GF127{1 + 1<<63, maxUint64>>1 - 1}, GF127{maxUint64 - 1, 5}},
|
|
|
|
},
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMul10x2(t *testing.T) {
|
|
|
|
c := new(GF127x2)
|
|
|
|
for _, tc := range testCasesMul10x2 {
|
2019-06-24 07:56:15 +00:00
|
|
|
Mul10x2(tc[0], c)
|
|
|
|
require.Equal(t, tc[1], c)
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testCasesMul11x2 = [][2]*GF127x2{
|
2019-10-10 08:04:15 +00:00
|
|
|
{
|
|
|
|
&GF127x2{GF127{123, 0}, GF127{123, 0}},
|
|
|
|
&GF127x2{GF127{141, 0}, GF127{141, 0}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&GF127x2{GF127{maxUint64, 2}, GF127{0, 1}},
|
|
|
|
&GF127x2{GF127{1, 7}, GF127{0, 3}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
&GF127x2{GF127{0, maxUint64 >> 1}, GF127{maxUint64, 2}},
|
|
|
|
&GF127x2{GF127{1 + 1<<63, 1}, GF127{1, 7}},
|
|
|
|
},
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMul11x2(t *testing.T) {
|
|
|
|
c := new(GF127x2)
|
|
|
|
for _, tc := range testCasesMul11x2 {
|
2019-06-24 07:56:15 +00:00
|
|
|
Mul11x2(tc[0], c)
|
|
|
|
require.Equal(t, tc[1], c)
|
2019-06-21 14:40:48 +00:00
|
|
|
}
|
|
|
|
}
|