-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_test.go
45 lines (35 loc) · 1.1 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
package versions
import (
"fmt"
"github.com/golang-infrastructure/go-shuffle"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSortVersionSlice(t *testing.T) {
// 读取测试文件中的版本号
versions, err := ReadVersionsFromFile("./test_data/fast_json_versions.txt")
assert.Nil(t, err)
// 顺序打乱
shuffle.Shuffle(versions)
// 排序
sortedVersions := SortVersionSlice(versions)
// 检查是否有序
for i := 1; i < len(sortedVersions); i++ {
assert.True(t, sortedVersions[i].CompareTo(sortedVersions[i-1]) >= 0)
}
for _, v := range sortedVersions {
fmt.Println(v.Raw)
}
}
func TestSortVersionStringSlice(t *testing.T) {
// 读取测试文件中的版本号
//versions, err := ReadVersionsStringFromFile("./test_data/fast_json_versions.txt")
versions, err := ReadVersionsStringFromFile("./test_data/org.apache.tomcat_tomcat-juli.txt")
assert.Nil(t, err)
shuffle.Shuffle(versions)
versions = SortVersionStringSlice(versions)
for i := 1; i < len(versions); i++ {
assert.True(t, NewVersion(versions[i]).CompareTo(NewVersion(versions[i-1])) >= 0)
t.Log(versions[i])
}
}