-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink_test.go
58 lines (48 loc) · 1.34 KB
/
link_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
package main
import (
"strings"
"testing"
)
func TestGetLinks(t *testing.T) {
flags := Flags{MinLinks: 5, MaxLinks: 20, MinLinkDepth: 1, MaxLinkDepth: 10}
for i := 0; i < 1000; i++ {
l := GetLinks(flags)
if len(l) < flags.MinLinks {
t.Errorf("%d links, expected %d or more", len(l), flags.MinLinks)
}
if len(l) > flags.MaxLinks {
t.Errorf("%d links, expected %d or less", len(l), flags.MaxLinks)
}
}
}
func TestGetLinkSegment(t *testing.T) {
for i := 0; i < 1000; i++ {
s := getLinkSegment(5, 25)
if len(s) < 5 || len(s) > 25 {
t.Errorf("link segment is %d long, expected between 5 - 25", len(s))
}
if strings.Contains(s, "/") {
t.Errorf("link segment %s, contains unexpected '/' character", s)
}
}
}
func TestGetLink(t *testing.T) {
flags := Flags{MinLinkDepth: 1, MaxLinkDepth: 10}
for i := 0; i < 1000; i++ {
l := getLink(flags)
depth := strings.Split(l, "/")
if len(depth) < flags.MinLinkDepth {
t.Errorf("link depth is %d, expected %d or more", len(depth), flags.MinLinkDepth)
}
if len(depth) > flags.MaxLinkDepth {
t.Errorf("link depth is %d, expected %d or less", len(depth), flags.MaxLinkDepth)
}
}
}
// --- benchmarks ---
func BenchmarkGetLinks(b *testing.B) {
flags := Flags{MinLinks: 5, MaxLinks: 20, MinLinkDepth: 1, MaxLinkDepth: 10}
for n := 0; n < b.N; n++ {
GetLinks(flags)
}
}