-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtokens_test.go
More file actions
171 lines (165 loc) · 4 KB
/
tokens_test.go
File metadata and controls
171 lines (165 loc) · 4 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package gomtch
import (
"reflect"
"testing"
)
func TestMakeTokens(t *testing.T) {
type args struct {
tokens []string
}
tests := []struct {
name string
args args
want Tokens
}{
{"default", args{tokens: []string{"something"}}, Tokens{
Values: map[int][]rune{
0: []rune("something"),
},
Ids: []int{0},
}},
{"twoWords", args{tokens: []string{"something", "else"}}, Tokens{
Values: map[int][]rune{
0: []rune("something"),
1: []rune("else"),
},
Ids: []int{0, 1},
}},
{"duplicatedWord", args{tokens: []string{"something", "else", "something"}}, Tokens{
Values: map[int][]rune{
0: []rune("something"),
1: []rune("else"),
},
Ids: []int{0, 1, 0},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewMappingFromTokens(tt.args.tokens).Map()
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("MakeTokens() = %v, want %v", got, tt.want)
}
})
}
}
func TestTokens_mapTokens(t1 *testing.T) {
type args struct {
m Mapping
}
tests := []struct {
name string
args args
want []int
}{
{"default", args{
m: NewMappingFromTokens([]string{"a", "b", "a", "c", "c", "a", "b", "d"}),
},
[]int{0, 1, 0, 3, 3, 0, 1, 7}},
}
for _, tt := range tests {
t1.Run(tt.name, func(t1 *testing.T) {
ids := tt.args.m.Map().Ids
if !reflect.DeepEqual(tt.want, ids) {
t1.Errorf("mapTokens() = %v, want %v", ids, tt.want)
}
})
}
}
func Test_makeMapping(t *testing.T) {
type args struct {
v []string
}
tests := []struct {
name string
args args
want Mapping
}{
{"default0", args{v: []string{"comida", "gostosa"}}, map[string][]int{
"comida": {0},
"gostosa": {1},
}},
{"duplicated", args{v: []string{"boa", "comida", "boa", "comida"}}, map[string][]int{
"boa": {0, 2},
"comida": {1, 3},
}},
{"default1", args{v: []string{"comida", "gostosa."}}, map[string][]int{
"comida": {0},
"gostosa": {1},
".": {2},
}},
{"default2", args{v: []string{"comida", ".gostosa"}}, map[string][]int{
"comida": {0},
".": {1},
"gostosa": {2},
}},
{"default3", args{v: []string{"comida:", ".gostosa"}}, map[string][]int{
"comida": {0},
":": {1},
".": {2},
"gostosa": {3},
}},
{"default4", args{v: []string{":comida:", ".gostosa"}}, map[string][]int{
":": {0, 2},
"comida": {1},
".": {3},
"gostosa": {4},
}},
{"default5", args{v: []string{":comida", ".gostosa"}}, map[string][]int{
":": {0},
"comida": {1},
".": {2},
"gostosa": {3},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewMappingFromTokens(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewMappingFromTokens() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getEndSpecial(t *testing.T) {
type args struct {
token []rune
}
tests := []struct {
name string
args args
want []rune
}{
{"default", args{token: []rune("amigo")}, nil},
{"endWithDot", args{token: []rune("amigo.")}, []rune(".")},
{"endWithManyDots", args{token: []rune("amigo...")}, []rune("...")},
{"endWithDotAndHasSpecialInside", args{token: []rune("amig.o.")}, []rune(".")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getEndSpecial(tt.args.token); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getEndSpecial() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getStartSpecial(t *testing.T) {
type args struct {
token []rune
}
tests := []struct {
name string
args args
want []rune
}{
{"default", args{token: []rune("amigo")}, nil},
{"startWithDot", args{token: []rune(".amigo")}, []rune(".")},
{"startWithManyDots", args{token: []rune("...amigo")}, []rune("...")},
{"startWithDotAndHasSpecialInside", args{token: []rune(".a.migo")}, []rune(".")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getStartSpecial(tt.args.token); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getStartSpecial() = %v, want %v", got, tt.want)
}
})
}
}