-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhitlist_test.go
62 lines (51 loc) · 1.05 KB
/
hitlist_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
package main
import (
"reflect"
"testing"
)
func TestRankSectionsByHits(t *testing.T) {
testHitsMap := map[string]int{
"/foo": 2,
"/foobar": 5,
"/barbaz": 4,
"/baz": 3,
"/bar": 1,
}
expected := HitList{
0: Pair{"/foobar", 5},
1: Pair{"/barbaz", 4},
2: Pair{"/baz", 3},
3: Pair{"/foo", 2},
4: Pair{"/bar", 1},
}
actual := RankByHits(testHitsMap) // *HitList
if !reflect.DeepEqual(expected, actual) {
t.Error("Failed RankSectionsByHits test!")
t.Log("Expected:")
t.Logf("%+v\n", expected)
t.Log("Actual:")
t.Logf("%+v\n", actual)
}
}
func TestCutTopN(t *testing.T) {
testHitList := HitList{
0: Pair{"/foobar", 5},
1: Pair{"/barbaz", 4},
2: Pair{"/baz", 3},
3: Pair{"/foo", 2},
4: Pair{"/bar", 1},
}
expected := HitList{
0: Pair{"/foobar", 5},
1: Pair{"/barbaz", 4},
2: Pair{"/baz", 3},
}
actual := CutTopN(testHitList, 3)
if !reflect.DeepEqual(expected, actual) {
t.Error("Failed CutTopN test!")
t.Log("Expected:")
t.Logf("%+v\n", expected)
t.Log("Actual:")
t.Logf("%+v\n", actual)
}
}