1
0
Fork 0
algorithms-go/sort/insertion_sort_test.go

39 lines
665 B
Go
Raw Normal View History

2015-10-11 21:32:38 +00:00
package sort
2015-10-11 21:11:00 +00:00
import (
"testing"
)
func TestInsertionSort(t *testing.T) {
testSort(t, InsertionSort,
2015-10-11 21:11:00 +00:00
[]int{5, 3, 1, 4, 2},
[]int{1, 2, 3, 4, 5},
)
}
func TestInsertionSortOptimized(t *testing.T) {
testSort(t, InsertionSortOptimized,
2015-10-11 21:11:00 +00:00
[]int{5, 3, 1, 4, 2},
[]int{1, 2, 3, 4, 5},
)
}
func TestInsertionSortOptimizedTwoItems(t *testing.T) {
testSort(t, InsertionSortOptimized,
2015-10-11 21:11:00 +00:00
[]int{2, 1},
[]int{1, 2},
)
}
func BenchmarkInsertionSort(b *testing.B) {
for i := 0; i < b.N; i++ {
InsertionSort(unsortedArray())
}
}
func BenchmarkInsertionSortOptimized(b *testing.B) {
for i := 0; i < b.N; i++ {
InsertionSortOptimized(unsortedArray())
}
}