-
Notifications
You must be signed in to change notification settings - Fork 122
/
tracker_sort_test.go
59 lines (49 loc) · 2.32 KB
/
tracker_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
package progress
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSortBy(t *testing.T) {
trackers := []*Tracker{
{Message: "Downloading File # 2", Total: 1000, value: 300},
{Message: "Downloading File # 1", Total: 1000, value: 100},
{Message: "Downloading File # 3", Total: 1000, value: 500},
{Message: "Downloading File # 4", Total: 1000, value: 300, timeStart: time.Now()},
}
SortByNone.Sort(trackers)
assert.Equal(t, "Downloading File # 2", trackers[0].Message)
assert.Equal(t, "Downloading File # 1", trackers[1].Message)
assert.Equal(t, "Downloading File # 3", trackers[2].Message)
assert.Equal(t, "Downloading File # 4", trackers[3].Message)
SortByMessage.Sort(trackers)
assert.Equal(t, "Downloading File # 1", trackers[0].Message)
assert.Equal(t, "Downloading File # 2", trackers[1].Message)
assert.Equal(t, "Downloading File # 3", trackers[2].Message)
assert.Equal(t, "Downloading File # 4", trackers[3].Message)
SortByMessageDsc.Sort(trackers)
assert.Equal(t, "Downloading File # 4", trackers[0].Message)
assert.Equal(t, "Downloading File # 3", trackers[1].Message)
assert.Equal(t, "Downloading File # 2", trackers[2].Message)
assert.Equal(t, "Downloading File # 1", trackers[3].Message)
SortByPercent.Sort(trackers)
assert.Equal(t, "Downloading File # 1", trackers[0].Message)
assert.Equal(t, "Downloading File # 2", trackers[1].Message)
assert.Equal(t, "Downloading File # 4", trackers[2].Message)
assert.Equal(t, "Downloading File # 3", trackers[3].Message)
SortByPercentDsc.Sort(trackers)
assert.Equal(t, "Downloading File # 3", trackers[0].Message)
assert.Equal(t, "Downloading File # 4", trackers[1].Message)
assert.Equal(t, "Downloading File # 2", trackers[2].Message)
assert.Equal(t, "Downloading File # 1", trackers[3].Message)
SortByValue.Sort(trackers)
assert.Equal(t, "Downloading File # 1", trackers[0].Message)
assert.Equal(t, "Downloading File # 2", trackers[1].Message)
assert.Equal(t, "Downloading File # 4", trackers[2].Message)
assert.Equal(t, "Downloading File # 3", trackers[3].Message)
SortByValueDsc.Sort(trackers)
assert.Equal(t, "Downloading File # 3", trackers[0].Message)
assert.Equal(t, "Downloading File # 4", trackers[1].Message)
assert.Equal(t, "Downloading File # 2", trackers[2].Message)
assert.Equal(t, "Downloading File # 1", trackers[3].Message)
}