Skip to content

Commit ae75e5d

Browse files
committed
add tests
1 parent 00fc33d commit ae75e5d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

coderd/util/slice/slice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func Difference[T comparable](a []T, b []T) []T {
132132
}
133133

134134
func SymmetricDifferenceFunc[T any](a, b []T, equal func(a, b T) bool) (add []T, remove []T) {
135-
return DifferenceFunc(a, b, equal), DifferenceFunc(b, a, equal)
135+
return DifferenceFunc(b, a, equal), DifferenceFunc(a, b, equal)
136136
}
137137

138138
func DifferenceFunc[T any](a []T, b []T, equal func(a, b T) bool) []T {

coderd/util/slice/slice_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,48 @@ func TestSymmetricDifference(t *testing.T) {
186186
require.ElementsMatch(t, []int{}, add)
187187
require.ElementsMatch(t, []int{}, remove)
188188
})
189+
190+
t.Run("ToEmpty", func(t *testing.T) {
191+
t.Parallel()
192+
193+
add, remove := slice.SymmetricDifference(
194+
[]int{1, 2, 3},
195+
[]int{},
196+
)
197+
require.ElementsMatch(t, []int{}, add)
198+
require.ElementsMatch(t, []int{1, 2, 3}, remove)
199+
})
200+
201+
t.Run("ToNil", func(t *testing.T) {
202+
t.Parallel()
203+
204+
add, remove := slice.SymmetricDifference(
205+
[]int{1, 2, 3},
206+
nil,
207+
)
208+
require.ElementsMatch(t, []int{}, add)
209+
require.ElementsMatch(t, []int{1, 2, 3}, remove)
210+
})
211+
212+
t.Run("FromEmpty", func(t *testing.T) {
213+
t.Parallel()
214+
215+
add, remove := slice.SymmetricDifference(
216+
[]int{},
217+
[]int{1, 2, 3},
218+
)
219+
require.ElementsMatch(t, []int{1, 2, 3}, add)
220+
require.ElementsMatch(t, []int{}, remove)
221+
})
222+
223+
t.Run("FromNil", func(t *testing.T) {
224+
t.Parallel()
225+
226+
add, remove := slice.SymmetricDifference(
227+
nil,
228+
[]int{1, 2, 3},
229+
)
230+
require.ElementsMatch(t, []int{1, 2, 3}, add)
231+
require.ElementsMatch(t, []int{}, remove)
232+
})
189233
}

0 commit comments

Comments
 (0)