-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
shingle_test.go
37 lines (34 loc) · 1.39 KB
/
shingle_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 edlib
import (
"reflect"
"testing"
)
func TestShingle(t *testing.T) {
type args struct {
str string
k int
}
tests := []struct {
name string
args args
want map[string]int
}{
{"shingle 1", args{"Radiohead", 2}, map[string]int{"Ra": 1, "ad": 2, "di": 1, "ea": 1, "he": 1, "io": 1, "oh": 1}},
{"shingle 1-1", args{"Radiohead", 3}, map[string]int{"Rad": 1, "adi": 1, "dio": 1, "ead": 1, "hea": 1, "ioh": 1, "ohe": 1}},
{"shingle 2", args{"I love horror movies", 2}, map[string]int{" h": 1, " l": 1, " m": 1, "I ": 1, "e ": 1, "es": 1, "ho": 1, "ie": 1, "lo": 1, "mo": 1, "or": 2, "ov": 2, "r ": 1, "ro": 1, "rr": 1, "ve": 1, "vi": 1}},
{"shingle 3", args{"私の名前はジョンです", 2}, map[string]int{"です": 1, "の名": 1, "はジ": 1, "ジョ": 1, "ョン": 1, "ンで": 1, "前は": 1, "名前": 1, "私の": 1}},
{"shingle 4", args{"🙂😄🙂😄 😄🙂😄", 2}, map[string]int{" 😄": 1, "😄 ": 1, "😄🙂": 2, "🙂😄": 3}},
{"shingle 5", args{"", 100}, make(map[string]int)},
{"shingle 6", args{"hello", 0}, make(map[string]int)},
{"shingle 7", args{"四畳半神話大系", 7}, map[string]int{"四畳半神話大系": 1}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Shingle(tt.args.str, tt.args.k)
eq := reflect.DeepEqual(got, tt.want)
if !eq {
t.Errorf("Shingle() = %v, want %v", got, tt.want)
}
})
}
}