forked from TrueCloudLab/tzhash
Use testify/require for testing
This commit is contained in:
parent
500c652dcc
commit
d9e26aa6de
2 changed files with 24 additions and 31 deletions
|
@ -2,6 +2,8 @@ package gf127
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxUint64 = ^uint64(0)
|
const maxUint64 = ^uint64(0)
|
||||||
|
@ -14,9 +16,7 @@ func TestAdd(t *testing.T) {
|
||||||
c = new(GF127)
|
c = new(GF127)
|
||||||
)
|
)
|
||||||
c.Add(a, b)
|
c.Add(a, b)
|
||||||
if e[0] != c[0] || e[1] != c[1] {
|
require.Equal(t, e, c)
|
||||||
t.Errorf("expected (%s), got (%s)", e.String(), c.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var testCasesMul = [][3]*GF127{
|
var testCasesMul = [][3]*GF127{
|
||||||
|
@ -33,9 +33,8 @@ var testCasesMul = [][3]*GF127{
|
||||||
func TestMul(t *testing.T) {
|
func TestMul(t *testing.T) {
|
||||||
c := new(GF127)
|
c := new(GF127)
|
||||||
for _, tc := range testCasesMul {
|
for _, tc := range testCasesMul {
|
||||||
if Mul(tc[0], tc[1], c); !c.Equals(tc[2]) {
|
Mul(tc[0], tc[1], c)
|
||||||
t.Errorf("expected (%s), got (%s)", c.String(), tc[2].String())
|
require.Equal(t, tc[2], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,9 +47,8 @@ var testCasesMul10 = [][2]*GF127{
|
||||||
func TestMul10(t *testing.T) {
|
func TestMul10(t *testing.T) {
|
||||||
c := new(GF127)
|
c := new(GF127)
|
||||||
for _, tc := range testCasesMul10 {
|
for _, tc := range testCasesMul10 {
|
||||||
if Mul10(tc[0], c); !c.Equals(tc[1]) {
|
Mul10(tc[0], c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc[1].String(), c.String())
|
require.Equal(t, tc[1], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +61,8 @@ var testCasesMul11 = [][2]*GF127{
|
||||||
func TestMul11(t *testing.T) {
|
func TestMul11(t *testing.T) {
|
||||||
c := new(GF127)
|
c := new(GF127)
|
||||||
for _, tc := range testCasesMul11 {
|
for _, tc := range testCasesMul11 {
|
||||||
if Mul11(tc[0], c); !c.Equals(tc[1]) {
|
Mul11(tc[0], c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc[1].String(), c.String())
|
require.Equal(t, tc[1], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +75,8 @@ var testCasesInv = [][2]*GF127{
|
||||||
func TestInv(t *testing.T) {
|
func TestInv(t *testing.T) {
|
||||||
var a, b, c = new(GF127), new(GF127), new(GF127)
|
var a, b, c = new(GF127), new(GF127), new(GF127)
|
||||||
for _, tc := range testCasesInv {
|
for _, tc := range testCasesInv {
|
||||||
if Inv(tc[0], c); !c.Equals(tc[1]) {
|
Inv(tc[0], c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc[1].String(), c.String())
|
require.Equal(t, tc[1], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
|
@ -90,8 +86,6 @@ func TestInv(t *testing.T) {
|
||||||
}
|
}
|
||||||
Inv(a, b)
|
Inv(a, b)
|
||||||
Mul(a, b, c)
|
Mul(a, b, c)
|
||||||
if !c.Equals(&GF127{1, 0}) {
|
require.Equal(t, &GF127{1, 0}, c)
|
||||||
t.Errorf("expected inverse of (%s), got (%s)", a.String(), b.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package gf127
|
package gf127
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
var testCasesSplit = []struct {
|
var testCasesSplit = []struct {
|
||||||
num *GF127x2
|
num *GF127x2
|
||||||
|
@ -14,9 +18,8 @@ var testCasesSplit = []struct {
|
||||||
func TestSplit(t *testing.T) {
|
func TestSplit(t *testing.T) {
|
||||||
for _, tc := range testCasesSplit {
|
for _, tc := range testCasesSplit {
|
||||||
a, b := Split(tc.num)
|
a, b := Split(tc.num)
|
||||||
if !a.Equals(tc.h1) || !b.Equals(tc.h2) {
|
require.Equal(t, tc.h1, a)
|
||||||
t.Errorf("expected (%s,%s), got (%s,%s)", tc.h1, tc.h2, a, b)
|
require.Equal(t, tc.h2, b)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +27,7 @@ func TestCombineTo(t *testing.T) {
|
||||||
c := new(GF127x2)
|
c := new(GF127x2)
|
||||||
for _, tc := range testCasesSplit {
|
for _, tc := range testCasesSplit {
|
||||||
CombineTo(tc.h1, tc.h2, c)
|
CombineTo(tc.h1, tc.h2, c)
|
||||||
if !c.Equal(tc.num) {
|
require.Equal(t, tc.num, c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc.num, c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +40,8 @@ var testCasesMul10x2 = [][2]*GF127x2{
|
||||||
func TestMul10x2(t *testing.T) {
|
func TestMul10x2(t *testing.T) {
|
||||||
c := new(GF127x2)
|
c := new(GF127x2)
|
||||||
for _, tc := range testCasesMul10x2 {
|
for _, tc := range testCasesMul10x2 {
|
||||||
if Mul10x2(tc[0], c); !c.Equal(tc[1]) {
|
Mul10x2(tc[0], c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc[1], c)
|
require.Equal(t, tc[1], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,7 @@ var testCasesMul11x2 = [][2]*GF127x2{
|
||||||
func TestMul11x2(t *testing.T) {
|
func TestMul11x2(t *testing.T) {
|
||||||
c := new(GF127x2)
|
c := new(GF127x2)
|
||||||
for _, tc := range testCasesMul11x2 {
|
for _, tc := range testCasesMul11x2 {
|
||||||
if Mul11x2(tc[0], c); !c.Equal(tc[1]) {
|
Mul11x2(tc[0], c)
|
||||||
t.Errorf("expected (%s), got (%s)", tc[1], c)
|
require.Equal(t, tc[1], c)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue