Handy and reusable functions that I have been using when writing tests for slices. All functions accept *testing.T
and you can use them directly in your unit tests.
At the moment the following functions are available:
Exactly
: The slices have to match exactly, including size and order of elements,Elements
: The slices have to match in size, but the order of the elements can be different.
ElementsMatch
, that has the same functionality.
Import the package alongside testing
import (
"testing"
"github.com/kampanosg/match"
)
You can then use it in your tests
func TestExample(t *testing.T) {
slice1 := []int{1, 2, 3}
slice2 := []int{1, 2, 3}
match.Exactly(t, slice1, slice2)
match.Elements(t, slice1, slice2)
}
A Makefile
is provided that allows you to build and test the module
make build
make test