-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction_test.go
82 lines (74 loc) · 1.58 KB
/
action_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"testing"
)
func TestAttachLeft(t *testing.T) {
words := make([]*Word, 0)
words = append(words,
makeRootWord(),
makeWord("ms.", "NNP", 1, 2),
makeWord("hang", "NNP", 2, 3),
makeWord("plays", "VBZ", 3, 0),
makeWord("elianti", "NNP", 4, 3),
makeWord(".", ".", 5, 3),
)
s := NewState(words)
AttachLeft(s, 3)
p, ok := s.arcs[4]
if !ok || p != 3 {
t.Error("parent's index must be 3")
}
AttachLeft(s, 3)
p, ok = s.arcs[5]
if !ok || p != 3 {
t.Error("parent's index must be 3")
}
if len(s.pending) != 4 {
t.Error("length of pending must be 4")
}
}
func TestAttachRight(t *testing.T) {
words := make([]*Word, 0)
words = append(words,
makeRootWord(),
makeWord("ms.", "NNP", 1, 2),
makeWord("hang", "NNP", 2, 3),
makeWord("plays", "VBZ", 3, 0),
makeWord("elianti", "NNP", 4, 3),
makeWord(".", ".", 5, 3),
)
s := NewState(words)
AttachRight(s, 3)
p, ok := s.arcs[3]
if !ok || p != 4 {
t.Error("parent's index must be 4")
}
AttachRight(s, 3)
p, ok = s.arcs[4]
if !ok || p != 5 {
t.Error("parent's index must be 5")
}
if len(s.pending) != 4 {
t.Error("length of pending must be 4")
}
}
func TestAttachLeftAll(t *testing.T) {
words := make([]*Word, 0)
words = append(words,
makeRootWord(),
makeWord("ms.", "NNP", 1, 2),
makeWord("hang", "NNP", 2, 3),
makeWord("plays", "VBZ", 3, 0),
makeWord("elianti", "NNP", 4, 3),
makeWord(".", ".", 5, 3),
)
s := NewState(words)
AttachLeft(s, 0)
AttachLeft(s, 0)
AttachLeft(s, 0)
AttachLeft(s, 0)
AttachLeft(s, 0)
if words[1].surface != "ms." {
t.Error("surface is wrong")
}
}