forked from client9/misspell
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
words_test.go
37 lines (31 loc) · 847 Bytes
/
words_test.go
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
34
35
36
37
package misspell
import (
"sort"
"testing"
)
type sortByLen []string
func (a sortByLen) Len() int { return len(a) }
func (a sortByLen) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a sortByLen) Less(i, j int) bool {
if len(a[i]) == len(a[j]) {
// if words are same size, then use
// normal alphabetical order
return a[i] < a[j]
}
// INVERTED -- biggest words first
return len(a[i]) > len(a[j])
}
func Test_wordSort(t *testing.T) {
if len(DictMain)%2 == 1 {
t.Errorf("Dictionary is a not a multiple of 2")
}
words := make([]string, 0, len(DictMain)/2)
for i := 0; i < len(DictMain); i += 2 {
words = append(words, DictMain[i])
}
if !sort.IsSorted(sortByLen(words)) {
t.Errorf("Words not sorted by len, by alpha!")
t.Errorf("Words.go is autogenerated -- do not edit.")
t.Errorf("File issue instead.")
}
}