github.com/gogf/selfupdate@v0.0.0-20231215043001-5c48c528462f/internal/binarydist/sort_test.go (about) 1 package binarydist 2 3 import ( 4 "bytes" 5 "crypto/rand" 6 "testing" 7 ) 8 9 var sortT = [][]byte{ 10 mustRandBytes(1000), 11 mustReadAll(mustOpen("test.old")), 12 []byte("abcdefabcdef"), 13 } 14 15 func TestQsufsort(t *testing.T) { 16 for _, s := range sortT { 17 I := qsufsort(s) 18 for i := 1; i < len(I); i++ { 19 if bytes.Compare(s[I[i-1]:], s[I[i]:]) > 0 { 20 t.Fatalf("unsorted at %d", i) 21 } 22 } 23 } 24 } 25 26 func mustRandBytes(n int) []byte { 27 b := make([]byte, n) 28 _, err := rand.Read(b) 29 if err != nil { 30 panic(err) 31 } 32 return b 33 }