Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slices: don't modify input slices in test #30677

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/slices/slices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math"
"math/rand"
"slices"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -63,10 +64,11 @@ func TestUnique(t *testing.T) {
func TestUniqueFunc(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
input := slices.Clone(tc.input)
got := UniqueFunc(
tc.input,
input,
func(i int) int {
return tc.input[i]
return input[i]
},
)
assert.ElementsMatch(t, tc.expected, got)
Expand All @@ -77,7 +79,8 @@ func TestUniqueFunc(t *testing.T) {
func TestSortedUnique(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := SortedUnique(tc.input)
input := slices.Clone(tc.input)
got := SortedUnique(input)
assert.ElementsMatch(t, tc.expected, got)
})
}
Expand All @@ -86,10 +89,11 @@ func TestSortedUnique(t *testing.T) {
func TestSortedUniqueFunc(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
input := slices.Clone(tc.input)
got := SortedUniqueFunc(
tc.input,
input,
func(i, j int) bool {
return tc.input[i] < tc.input[j]
return input[i] < input[j]
},
func(a, b int) bool {
return a == b
Expand Down