-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexorank_test.go
80 lines (75 loc) · 1.9 KB
/
lexorank_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package lexorank
import (
"fmt"
"reflect"
"testing"
)
func TestRank(t *testing.T) {
testCases := []struct {
prev, next string
want string
wantErr bool
}{
{"", "", "U", false},
{"", "0", "0", false},
{"", "2", "1", false},
{"x", "", "y", false},
{"aaaa", "aaab", "aaaaU", false},
{"aaaa", "aaac", "aaab", false},
{"az", "b", "azU", false},
{"a", "d", "b", false},
{"a", "c", "b", false},
{"aaaa", "aaaa", "aaaa", false},
{"a", "a0", "a", false},
{"a", "", "m", false},
{"", "0", "0", false},
{"z", "", "z", false},
{"_", "", "", true},
{"", "*", "", true},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("case %d: (%q..%q)", i, tc.prev, tc.next), func(t *testing.T) {
got, err := Rank(tc.prev, tc.next)
if err != nil {
if tc.wantErr {
return
}
t.Errorf("unexpected error: %v", err)
return
}
if got != tc.want {
t.Errorf("want %q, got %q", tc.want, got)
}
})
}
}
func TestRankN(t *testing.T) {
testCases := []struct {
prev, next string
n int
want []string
wantErr bool
}{
{"", "", 5, []string{"U0", "U1", "U2", "U3", "U4"}, false},
{"az", "b", 3, []string{"azU0", "azU1", "azU2"}, false},
{"a", "d", 2, []string{"b0", "b1"}, false},
{"a", "c", 4, []string{"b0", "b1", "b2", "b3"}, false},
{"0", "z", 20, []string{"U00", "U01", "U02", "U03", "U04", "U05", "U06", "U07", "U08", "U09", "U10", "U11", "U12", "U13", "U14", "U15", "U16", "U17", "U18", "U19"}, false},
{"a", "_", 4, []string{"b0", "b1", "b2", "b3"}, true},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("case %d: (%q..%q)", i, tc.prev, tc.next), func(t *testing.T) {
got, err := RankN(tc.prev, tc.next, tc.n)
if err != nil {
if tc.wantErr {
return
}
t.Errorf("unexpected error: %v", err)
return
}
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("want %#v, got %#v", tc.want, got)
}
})
}
}