|
1 | 1 | package _1_sorts |
2 | 2 |
|
3 | 3 | import ( |
| 4 | +"fmt" |
4 | 5 | "testing" |
5 | 6 | ) |
6 | 7 |
|
7 | 8 | func TestBubbleSort(t *testing.T) { |
8 | | -a := []int{5, 4, 3, 2, 1} |
9 | | -BubbleSort(a) |
10 | | -t.Log(a) |
| 9 | +arr := []int{1,5,9,6,3,7,5,10} |
| 10 | +fmt.Println("排序前:",arr) |
| 11 | +BubbleSort(arr,len(arr)) |
| 12 | +fmt.Println("排序后:",arr) |
11 | 13 | } |
12 | 14 |
|
13 | | -func TestSelectionSort(t *testing.T) { |
14 | | -a := []int{5, 4, 3, 2, 1} |
15 | | -SelectionSort(a) |
16 | | -t.Log(a) |
17 | | -} |
18 | | -func TestInsertSort(t *testing.T) { |
19 | | -a := []int{5, 4, 3, 2, 1} |
20 | | -InsertSort(a) |
21 | | -t.Log(a) |
22 | | -} |
23 | | - |
24 | | -func BenchmarkBubbleSort(b *testing.B) { |
25 | | -a := []int{5, 4, 3, 2, 1} |
26 | | -for i := 0; i < b.N; i++ { |
27 | | -BubbleSort(a) |
28 | | -} |
| 15 | +func TestInsertionSort(t *testing.T) { |
| 16 | +arr := []int{1,5,9,6,3,7,5,10} |
| 17 | +fmt.Println("排序前:",arr) |
| 18 | +InsertionSort(arr,len(arr)) |
| 19 | +fmt.Println("排序后:",arr) |
29 | 20 | } |
30 | 21 |
|
31 | | -func BenchmarkSelectionSort(b *testing.B) { |
32 | | -a := []int{5, 4, 3, 2, 1} |
33 | | -for i := 0; i < b.N; i++ { |
34 | | -SelectionSort(a) |
35 | | -} |
36 | | -} |
37 | | - |
38 | | -func BenchmarkInsertSort(b *testing.B) { |
39 | | -a := []int{5, 4, 3, 2, 1} |
40 | | -for i := 0; i < b.N; i++ { |
41 | | -InsertSort(a) |
42 | | -} |
| 22 | +func TestSelectionSort(t *testing.T) { |
| 23 | +arr := []int{1,5,9,6,3,7,5,10} |
| 24 | +fmt.Println("排序前:",arr) |
| 25 | +SelectionSort(arr,len(arr)) |
| 26 | +fmt.Println("排序后:",arr) |
43 | 27 | } |
0 commit comments