mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 20:47:11 +00:00
27 lines
515 B
Go
27 lines
515 B
Go
// Copyright © 2018 ChaiShushan <chaishushan{AT}gmail.com>.
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
package qsort
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
func TestSort(t *testing.T) {
|
|
values := []int32{42, 9, 101, 95, 27, 25}
|
|
|
|
Sort(unsafe.Pointer(&values[0]),
|
|
len(values), int(unsafe.Sizeof(values[0])),
|
|
t_get_go_qsort_compare(),
|
|
)
|
|
|
|
isSorted := sort.SliceIsSorted(values, func(i, j int) bool {
|
|
return values[i] < values[j]
|
|
})
|
|
if !isSorted {
|
|
t.Fatal("should be sorted")
|
|
}
|
|
}
|