-
Notifications
You must be signed in to change notification settings - Fork 0
/
scorer_test.go
126 lines (106 loc) · 2.61 KB
/
scorer_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package gobstract
import (
"testing"
)
func TestNewScorer(t *testing.T) {
var s *scorer = newScorer(make(sentences, 10))
if s.limit != minSummary {
t.Errorf("Expected %d (min), got %d", minSummary, s.limit)
}
s = newScorer(make(sentences, 50))
var expected int = int(50 * summaryPercent)
if s.limit != expected {
t.Errorf("Expected %d, got %d", expected, s.limit)
}
}
func TestCalcRelations(t *testing.T) {
var ps sentences = sentences{
{tokens: []string{"aaaa"}, lengthTokens: 1},
{tokens: []string{"aaaa"}, lengthTokens: 1},
{tokens: []string{"bbbb"}, lengthTokens: 1},
{tokens: []string{"cccc"}, lengthTokens: 1},
{tokens: []string{"dddd"}, lengthTokens: 1},
}
var s *scorer = newScorer(ps)
s.calcRelations()
if s.phrases[0].weight != 1 {
t.Errorf("Expected 1, got %f", s.phrases[0].weight)
}
if s.phrases[1].weight != 1 {
t.Errorf("Expected 1, got %f", s.phrases[1].weight)
}
for _, p := range s.phrases[2:] {
if p.weight != 0 {
t.Errorf("Expected 0, got %f", p.weight)
}
}
s = newScorer(ps[2:])
s.calcRelations()
for _, p := range s.phrases {
if p.weight != 0 {
t.Errorf("Expected 0, got %f", p.weight)
}
}
}
func TestCalcLength(t *testing.T) {
var ps sentences = sentences{
{lengthRaw: 170, weight: 3},
{lengthRaw: 140, weight: 3},
{lengthRaw: 90, weight: 1},
{lengthRaw: 90, weight: 1},
{lengthRaw: 90, weight: 1},
}
var s *scorer = newScorer(ps)
s.calcLength()
if 3 >= s.phrases[0].weight {
t.Errorf("Expected > 3, got %f", s.phrases[0].weight)
}
if 3 >= s.phrases[1].weight {
t.Errorf("Expected > 3, got %f", s.phrases[1].weight)
}
for _, p := range s.phrases[2:] {
if p.weight != 1 {
t.Errorf("Expected 1, got %f", p.weight)
}
}
ps = sentences{
{lengthRaw: 170, weight: 0},
{lengthRaw: 140, weight: 0},
{lengthRaw: 90, weight: 0},
{lengthRaw: 90, weight: 0},
{lengthRaw: 90, weight: 0},
}
s = newScorer(ps)
s.calcLength()
for _, p := range s.phrases {
if p.weight != 0 {
t.Errorf("Expected 0, got %f", p.weight)
}
}
}
func TestCalcPosition(t *testing.T) {
var ps sentences = sentences{
{weight: 3, order: 1},
{weight: 3, order: 2},
{weight: 3, order: 3},
{weight: 1, order: 4},
{weight: 1, order: 5},
{weight: 1, order: 6},
{weight: 1, order: 7},
{weight: 3, order: 8},
{weight: 3, order: 9},
{weight: 3, order: 10},
}
var s *scorer = newScorer(ps)
s.calcPosition()
for _, p := range s.phrases[3:7] {
if p.weight != 1 {
t.Errorf("Expected 1, got %f", p.weight)
}
}
for _, p := range append(s.phrases[:3], s.phrases[7:]...) {
if p.weight <= 3 {
t.Errorf("Expected > 3, got %f", p.weight)
}
}
}