Skip to content

Commit

Permalink
Introduced testVector struct and simplified test cases
Browse files Browse the repository at this point in the history
Extracted common test code to a separate function.
  • Loading branch information
pdyraga committed Jun 18, 2019
1 parent 209d276 commit 475f5b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 34 deletions.
33 changes: 15 additions & 18 deletions f_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,15 @@ import (
)

func TestF_2b(t *testing.T) {
for i, test := range testVectors_2b {
t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
mHex, err := hex.DecodeString(test.mIn)
if err != nil {
t.Fatal(err)
}

h := test.hIn
c := test.c

F(&h, mHex, &c, test.f, test.rounds)

if !reflect.DeepEqual(test.hOut, h) {
t.Errorf("Unexpected result\nExpected: [%v]\nActual: [%v]\n", test.hOut, h)
}
})
}
runTest(t, testVectors2b)
}

func TestF_2bX(t *testing.T) {
for i, test := range testVectors_2bX {
runTest(t, testVectors2bX)
}

func runTest(t *testing.T, testVectors []testVector) {
for i, test := range testVectors {
t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
mHex, err := hex.DecodeString(test.mIn)
if err != nil {
Expand All @@ -46,3 +34,12 @@ func TestF_2bX(t *testing.T) {
})
}
}

type testVector struct {
mIn string
hIn [8]uint64
c [2]uint64
f bool
rounds int
hOut [8]uint64
}
9 changes: 1 addition & 8 deletions f_vectors_2b_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ package blake2

// Test vectors generated from golang.org/x/crypto/blake2b TestHashes vectors
// - every unique hashBlocks invocation is covered here.
var testVectors_2b = []struct {
mIn string
hIn [8]uint64
c [2]uint64
f bool
rounds int
hOut [8]uint64
}{
var testVectors2b = []testVector{
// 0
{
mIn: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
Expand Down
9 changes: 1 addition & 8 deletions f_vectors_2bx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ package blake2

// Test vectors generated from golang.org/x/crypto/blake2b TestHashes2X vectors
// - every unique hashBlocks invocation is covered here.
var testVectors_2bX = []struct {
mIn string
hIn [8]uint64
c [2]uint64
f bool
rounds int
hOut [8]uint64
}{
var testVectors2bX = []testVector {
// 0
{
mIn: "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
Expand Down

0 comments on commit 475f5b8

Please sign in to comment.