From d07d6f33714c2b1213a6b13ac43ce4ae16f0f7e0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 6 Feb 2020 11:56:34 +0300 Subject: [PATCH] util: refactor tests for ArrayReverse --- pkg/util/array_test.go | 43 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/pkg/util/array_test.go b/pkg/util/array_test.go index da0ef9448..d763665e4 100644 --- a/pkg/util/array_test.go +++ b/pkg/util/array_test.go @@ -6,24 +6,31 @@ import ( "github.com/stretchr/testify/require" ) -func TestArrayEvenReverse(t *testing.T) { - arr := []byte{0x01, 0x02, 0x03, 0x04} - have := ArrayReverse(arr) - want := []byte{0x04, 0x03, 0x02, 0x01} - require.Equal(t, want, have) +var testCases = []struct { + arr []byte + rev []byte +}{ + { + arr: []byte{}, + rev: []byte{}, + }, + { + arr: []byte{0x01}, + rev: []byte{0x01}, + }, + { + arr: []byte{0x01, 0x02, 0x03, 0x04}, + rev: []byte{0x04, 0x03, 0x02, 0x01}, + }, + { + arr: []byte{0x01, 0x02, 0x03, 0x04, 0x05}, + rev: []byte{0x05, 0x04, 0x03, 0x02, 0x01}, + }, } -func TestArrayOddReverse(t *testing.T) { - arr := []byte{0x01, 0x02, 0x03, 0x04, 0x05} - have := ArrayReverse(arr) - want := []byte{0x05, 0x04, 0x03, 0x02, 0x01} - require.Equal(t, want, have) -} - -// This tests a bug that occurred with arrays of size 1 -func TestArrayReverseLen2(t *testing.T) { - arr := []byte{0x01} - have := ArrayReverse(arr) - want := []byte{0x01} - require.Equal(t, want, have) +func TestArrayReverse(t *testing.T) { + for _, tc := range testCases { + have := ArrayReverse(tc.arr) + require.Equal(t, tc.rev, have) + } }