-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph_test.go
63 lines (52 loc) · 1.31 KB
/
graph_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
package textrank
import "testing"
func TestNewGraph(t *testing.T) {
graph := *newGraph([]string{"A", "B", "A", "C", "B"})
if len(graph) != 3 {
t.Errorf("graph length = %d, expected 3", len(graph))
}
if graph[0].Text != "A" {
t.Errorf("graph[0] = %s, expected A", graph[0].Text)
}
if graph[1].Text != "B" {
t.Errorf("graph[0] = %s, expected B", graph[1].Text)
}
if graph[2].Text != "C" {
t.Errorf("graph[0] = %s, expected C", graph[2].Text)
}
}
func TestAddNode(t *testing.T) {
graph := textgraph{}
graph.addNode("some-text", 1)
if len(graph) != 1 {
t.Errorf("graph length = %d, expected 1", len(graph))
}
}
func TestGetExistingNode(t *testing.T) {
graph := textgraph{}
graph.addNode("A", 1)
graph.addNode("B", 2)
node := graph.getNode("B")
if node.Text != "B" {
t.Errorf("node text = %s, expected B", node.Text)
}
}
func TestGetNonExistingNode(t *testing.T) {
graph := textgraph{}
node := graph.getNode("A")
if node != nil {
t.Errorf("node = %#v, expected nil", node)
}
}
func TestNormalizeGraph(t *testing.T) {
graph := textgraph{}
graph.addNode("A", 1)
graph.addNode("B", 2)
norm := graph.normalize()
if len(norm) != 2 {
t.Errorf("normalized length = %d, expected 2", len(norm))
}
if !eqStringSlices(norm, []string{"B", "A"}) {
t.Errorf("normalized = %#v, expected [B, A]", norm)
}
}