-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsortDescriptor_test.go
More file actions
45 lines (39 loc) · 878 Bytes
/
sortDescriptor_test.go
File metadata and controls
45 lines (39 loc) · 878 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
38
39
40
41
42
43
44
45
package fpgo
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type TestCustomObject struct {
Name ComparableString
Age int
Height float64
}
func TestSortDescriptor(t *testing.T) {
objects := []TestCustomObject{
{
Name: NewComparableString("BC"),
Age: 30,
},
{
Name: NewComparableString("AD"),
Age: 30,
},
{
Name: NewComparableString("AB"),
Age: 50,
},
}
objects = NewSortDescriptorsBuilder[TestCustomObject]().
ThenWithTransformerFunctor(func(obj TestCustomObject) Comparable[interface{}] {
return NewComparableOrdered(obj.Age)
}, false).
ThenWithFieldName("Name", true).
ToSortedList(objects...)
assert.Equal(t, 3, len(objects))
testOrder := ""
for _, object := range objects {
testOrder += fmt.Sprintf("%v%v/", object.Name.Val, object.Age)
}
assert.Equal(t, "AB50/AD30/BC30/", testOrder)
}