Skip to content

Commit

Permalink
Repackage test to add Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Edge authored and MatthewEdge committed Dec 11, 2023
1 parent 28ced0e commit 90280f0
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions slice/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package slice
package slice_test

import (
"fmt"
"testing"

"github.com/mailgun/holster/v4/slice"
"github.com/stretchr/testify/assert"
)

func ExampleRemove() {
s := []string{"1", "2", "3"}
i := []int{1, 2, 3}

fmt.Println(slice.Remove(s, 0, 2))
fmt.Println(slice.Remove(i, 1, 2))
// Output:
// [3]
// [1 3]
}

func ExampleRemoveAll() {
s := []int{1, 2, 3, 2, 4, 2}
fmt.Println(slice.RemoveAll(s, 2))
// Output: [1 3 4]
}

func TestRemove(t *testing.T) {
for _, test := range []struct {
name string
Expand Down Expand Up @@ -55,7 +74,7 @@ func TestRemove(t *testing.T) {
outSlice: nil,
}, {}} {
t.Run(test.name, func(t *testing.T) {
got := Remove(test.inSlice, test.i, test.j)
got := slice.Remove(test.inSlice, test.i, test.j)
for i, expected := range test.outSlice {
assert.Equal(t, expected, got[i])
}
Expand Down Expand Up @@ -111,7 +130,7 @@ func TestRemoveAll(t *testing.T) {
outSlice: []string{"foo", "bar", "baz.com"},
}} {
t.Run(test.name, func(t *testing.T) {
out := RemoveAll(test.inSlice, test.remove)
out := slice.RemoveAll(test.inSlice, test.remove)
for i, expected := range test.outSlice {
assert.Equal(t, expected, out[i])
}
Expand All @@ -127,7 +146,7 @@ func BenchmarkRemove(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
o = Remove(in, 2, 4)
o = slice.Remove(in, 2, 4)
}
out = o
}
Expand All @@ -138,7 +157,7 @@ func BenchmarkRemoveAll(b *testing.B) {

b.ResetTimer()
for i := 0; i < b.N; i++ {
o = RemoveAll(in, "localhost")
o = slice.RemoveAll(in, "localhost")
}
out = o
}

0 comments on commit 90280f0

Please sign in to comment.