forked from hbollon/go-edlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshingle_test.go
More file actions
37 lines (34 loc) ยท 1.39 KB
/
shingle_test.go
File metadata and controls
37 lines (34 loc) ยท 1.39 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
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)
}
})
}
}