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
|
package hugolib
import (
"fmt"
"github.com/stretchr/testify/assert"
"path/filepath"
"testing"
"github.com/spf13/hugo/source"
)
func TestPageSortReverse(t *testing.T) {
p := createSortTestPages(10)
assert.Equal(t, 0, p[0].FuzzyWordCount)
assert.Equal(t, 9, p[9].FuzzyWordCount)
p = p.Reverse()
assert.Equal(t, 9, p[0].FuzzyWordCount)
assert.Equal(t, 1, p[9].FuzzyWordCount)
}
func BenchmarkSortByWeightAndReverse(b *testing.B) {
p := createSortTestPages(300)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p = p.ByWeight().Reverse()
}
}
func createSortTestPages(num int) Pages {
pages := make(Pages, num)
for i := 0; i < num; i++ {
pages[i] = &Page{
Node: Node{
URLPath: URLPath{
Section: "z",
URL: fmt.Sprintf("http://base/x/y/p%d.html", i),
},
Site: &SiteInfo{
BaseURL: "http://base/",
},
},
Source: Source{File: *source.NewFile(filepath.FromSlash(fmt.Sprintf("/x/y/p%d.md", i)))},
}
w := 5
if i%2 == 0 {
w = 10
}
pages[i].FuzzyWordCount = i
pages[i].Weight = w
}
return pages
}
|