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
import (
"fmt"
"testing"
)
func TestBubbleSort(t *testing.T) {
a := []int{5, 4, 3, 2, 1}
BubbleSort(a)
t.Log(a)
arr := []int{1,5,9,6,3,7,5,10}
fmt.Println("排序前:",arr)
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) {
a := []int{5, 4, 3, 2, 1}
SelectionSort(a)
t.Log(a)
}
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)
}
arr := []int{1,5,9,6,3,7,5,10}
fmt.Println("排序前:",arr)
SelectionSort(arr,len(arr))
fmt.Println("排序后:",arr)
}