Skip to content

Commit e66eb16

Browse files
committed
Update slice test
1 parent 0fc8216 commit e66eb16

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

slice_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func TestSortSlice(t *testing.T) {
1616
sort.Strings(sorted)
1717

1818
a := data[0:]
19+
SortSlice(a, func(i int) string { return a[i] })
1920
if !reflect.DeepEqual(a, sorted) {
2021
t.Errorf(" got %v", a)
2122
t.Errorf("want %v", sorted)
@@ -53,6 +54,31 @@ func TestSortSlice1k(t *testing.T) {
5354
}
5455
}
5556

57+
func TestSortSliceBible(t *testing.T) {
58+
var data []string
59+
f, err := os.Open("res/bible.txt")
60+
if err != nil {
61+
log.Fatal(err)
62+
}
63+
for sc := bufio.NewScanner(f); sc.Scan(); {
64+
data = append(data, sc.Text())
65+
}
66+
67+
sorted := make([]string, len(data))
68+
copy(sorted, data)
69+
sort.Strings(sorted)
70+
71+
SortSlice(data, func(i int) string { return data[i] })
72+
if !reflect.DeepEqual(data, sorted) {
73+
for i, s := range data {
74+
if s != sorted[i] {
75+
t.Errorf("%v got: %v", i, s)
76+
t.Errorf("%v want: %v\n\n", i, sorted[i])
77+
}
78+
}
79+
}
80+
}
81+
5682
func BenchmarkRadixSortSliceBible(b *testing.B) {
5783
b.StopTimer()
5884
var data []string

0 commit comments

Comments
 (0)