-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsort_test.go
More file actions
37 lines (30 loc) · 621 Bytes
/
sort_test.go
File metadata and controls
37 lines (30 loc) · 621 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gfx
import (
"cmp"
"slices"
"testing"
)
func TestSortSliceInts(t *testing.T) {
s := []int{3, 1, 4, 1, 5, 9, 2, 6}
SortSlice(s, cmp.Compare[int])
if want := []int{1, 1, 2, 3, 4, 5, 6, 9}; !slices.Equal(s, want) {
t.Fatalf("SortSlice = %v, want %v", s, want)
}
}
func TestSortSliceCustom(t *testing.T) {
type item struct {
Key string
Value int
}
s := []item{
{"b", 2},
{"a", 1},
{"c", 3},
}
SortSlice(s, func(a, b item) int {
return cmp.Compare(a.Key, b.Key)
})
if s[0].Key != "a" || s[1].Key != "b" || s[2].Key != "c" {
t.Fatalf("SortSlice = %v, want sorted by Key", s)
}
}