-
Notifications
You must be signed in to change notification settings - Fork 2
/
word_test.go
57 lines (50 loc) · 1.23 KB
/
word_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
package textrank
import (
"strings"
"testing"
)
func TestLinkWords(t *testing.T) {
graph := textgraph{}
sentence := "1 2 3 4 5"
links := map[string][]string{
"1": []string{"2"},
"2": []string{"1", "3"},
"3": []string{"2", "4"},
"4": []string{"3", "5"},
"5": []string{"4"},
}
// Setup graph with nodes.
for _, word := range strings.Split(sentence, " ") {
graph.addNode(word, 0)
}
linkWords(&graph, []string{sentence})
for _, node := range graph {
nodeEdges := []string{}
for _, edge := range node.Edges {
nodeEdges = append(nodeEdges, edge.Text)
}
for word, wordLinks := range links {
if node.Text == word && !eqStringSlices(nodeEdges, wordLinks) {
t.Errorf("%s: edges = %v, expected %v",
word, nodeEdges, wordLinks)
}
}
}
}
func TestCleanText(t *testing.T) {
cases := map[string]struct {
Text string
ExpectedText []string
}{
"stopwords": {"is the a", []string{}},
"stopwords cases": {"iS ThE A", []string{}},
"mixed": {"the fox jumped", []string{"fox", "jumped"}},
}
for k, tc := range cases {
cleaned := cleanText(tc.Text)
if !eqStringSlices(cleaned, tc.ExpectedText) {
t.Errorf("%s: cleaned = %v, expected %v",
k, cleaned, tc.ExpectedText)
}
}
}