MCPcopy Index your code
hub / github.com/hustcc/JS-Sorting-Algorithm / test_func

Function test_func

src/goSortTest.go:43–62  ·  view source on GitHub ↗

测试 sort func 是否有效

(num int, sort func(arr []int) []int)

Source from the content-addressed store, hash-verified

41
42// 测试 sort func 是否有效
43func test_func(num int, sort func(arr []int) []int) {
44 r := rand.New(rand.NewSource(time.Now().UnixNano()))
45 src := initArray(num)
46 dest := make([]int, len(src))
47 perm := r.Perm(len(src))
48 for i, v := range perm {
49 dest[v] = src[i]
50 }
51
52 // fmt.Println(src)
53 // fmt.Println(dest)
54 result := sort(dest)
55 // fmt.Println(result)
56
57 if compare(src, result) {
58 fmt.Println("Test passed")
59 } else {
60 fmt.Println("Test failed")
61 }
62}
63
64// bubble sort
65func bubbleSort(arr []int) []int {

Callers 1

mainFunction · 0.85

Calls 2

initArrayFunction · 0.85
compareFunction · 0.85

Tested by

no test coverage detected