forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_test.go
59 lines (54 loc) · 1.01 KB
/
sort_test.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build !integration
// +build !integration
package disgord
import (
"testing"
)
func TestSort(t *testing.T) {
t.Run("name", func(t *testing.T) {
sameOrder := func(a, b []*Role) bool {
for i := range a {
if a[i].Name != b[i].Name {
return false
}
}
return true
}
roles := []*Role{
{Name: "b"},
{Name: "k"},
{Name: "j"},
{Name: "a"},
{Name: "e"},
{Name: "g"},
}
rolesAsc := []*Role{
{Name: "a"},
{Name: "b"},
{Name: "e"},
{Name: "g"},
{Name: "j"},
{Name: "k"},
}
rolesDesc := []*Role{
{Name: "k"},
{Name: "j"},
{Name: "g"},
{Name: "e"},
{Name: "b"},
{Name: "a"},
}
t.Run("ascending", func(t *testing.T) {
Sort(roles, SortByName)
if !sameOrder(roles, rolesAsc) {
t.Error("roles were not sorted into ascending order")
}
})
t.Run("descending", func(t *testing.T) {
Sort(roles, SortByName, OrderDescending)
if !sameOrder(roles, rolesDesc) {
t.Error("roles were not sorted into descending order")
}
})
})
}