Update Sort_test.go

This commit is contained in:
李柏林 2018-10-16 11:20:12 +08:00 committed by GitHub
parent 4e0649eee5
commit cba17d27b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,43 +1,27 @@
package _1_sorts package _1_sorts
import ( import (
"fmt"
"testing" "testing"
) )
func TestBubbleSort(t *testing.T) { func TestBubbleSort(t *testing.T) {
a := []int{5, 4, 3, 2, 1} arr := []int{1,5,9,6,3,7,5,10}
BubbleSort(a) fmt.Println("排序前:",arr)
t.Log(a) BubbleSort(arr,len(arr))
fmt.Println("排序后:",arr)
}
func TestInsertionSort(t *testing.T) {
arr := []int{1,5,9,6,3,7,5,10}
fmt.Println("排序前:",arr)
InsertionSort(arr,len(arr))
fmt.Println("排序后:",arr)
} }
func TestSelectionSort(t *testing.T) { func TestSelectionSort(t *testing.T) {
a := []int{5, 4, 3, 2, 1} arr := []int{1,5,9,6,3,7,5,10}
SelectionSort(a) fmt.Println("排序前:",arr)
t.Log(a) SelectionSort(arr,len(arr))
} fmt.Println("排序后:",arr)
func TestInsertSort(t *testing.T) {
a := []int{5, 4, 3, 2, 1}
InsertSort(a)
t.Log(a)
}
func BenchmarkBubbleSort(b *testing.B) {
a := []int{5, 4, 3, 2, 1}
for i := 0; i < b.N; i++ {
BubbleSort(a)
}
}
func BenchmarkSelectionSort(b *testing.B) {
a := []int{5, 4, 3, 2, 1}
for i := 0; i < b.N; i++ {
SelectionSort(a)
}
}
func BenchmarkInsertSort(b *testing.B) {
a := []int{5, 4, 3, 2, 1}
for i := 0; i < b.N; i++ {
InsertSort(a)
}
} }