Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
its-josh4 committed Oct 10, 2024
1 parent 509edda commit 6452ea6
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkg/sliceutil/collections_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sliceutil

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -66,3 +67,79 @@ func TestSliceSame(t *testing.T) {
})
}
}

func TestAppendUniques(t *testing.T) {
type args struct {
vs []int
toAdd []int
}
tests := []struct {
name string
args args
want []int
}{
{
name: "append to empty slice",
args: args{
vs: []int{},
toAdd: []int{1, 2, 3},
},
want: []int{1, 2, 3},
},
{
name: "append all unique values",
args: args{
vs: []int{1, 2, 3},
toAdd: []int{4, 5, 6},
},
want: []int{1, 2, 3, 4, 5, 6},
},
{
name: "append with some duplicates",
args: args{
vs: []int{1, 2, 3},
toAdd: []int{3, 4, 5},
},
want: []int{1, 2, 3, 4, 5},
},
{
name: "append all duplicates",
args: args{
vs: []int{1, 2, 3},
toAdd: []int{1, 2, 3},
},
want: []int{1, 2, 3},
},
{
name: "append to nil slice",
args: args{
vs: nil,
toAdd: []int{1, 2, 3},
},
want: []int{1, 2, 3},
},
{
name: "append empty slice",
args: args{
vs: []int{1, 2, 3},
toAdd: []int{},
},
want: []int{1, 2, 3},
},
{
name: "append nil to slice",
args: args{
vs: []int{1, 2, 3},
toAdd: nil,
},
want: []int{1, 2, 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := AppendUniques(tt.args.vs, tt.args.toAdd); !reflect.DeepEqual(got, tt.want) {
t.Errorf("AppendUniques() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 6452ea6

Please sign in to comment.