File: sort_test.go

package info (click to toggle)
golang-github-kr-binarydist 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 140 kB
  • sloc: makefile: 13
file content (33 lines) | stat: -rw-r--r-- 510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package binarydist

import (
	"bytes"
	"crypto/rand"
	"testing"
)

var sortT = [][]byte{
	mustRandBytes(1000),
	mustReadAll(mustOpen("test.old")),
	[]byte("abcdefabcdef"),
}

func TestQsufsort(t *testing.T) {
	for _, s := range sortT {
		I := qsufsort(s)
		for i := 1; i < len(I); i++ {
			if bytes.Compare(s[I[i-1]:], s[I[i]:]) > 0 {
				t.Fatalf("unsorted at %d", i)
			}
		}
	}
}

func mustRandBytes(n int) []byte {
	b := make([]byte, n)
	_, err := rand.Read(b)
	if err != nil {
		panic(err)
	}
	return b
}