metrics: Adjust the howSimilar logic vs strings

Also add a test.
This commit is contained in:
Bjørn Erik Pedersen
2019-04-02 20:43:58 +02:00
parent e91e222cd2
commit 4494a01b79
2 changed files with 14 additions and 10 deletions

View File

@@ -17,6 +17,8 @@ import (
"strings"
"testing"
"github.com/gohugoio/hugo/resources/page"
"github.com/stretchr/testify/require"
)
@@ -40,6 +42,12 @@ func TestSimilarPercentage(t *testing.T) {
}
func TestSimilarPercentageNonString(t *testing.T) {
assert := require.New(t)
assert.Equal(100, howSimilar(page.NopPage, page.NopPage))
assert.Equal(90, howSimilar(page.Pages{}, page.Pages{}))
}
func BenchmarkHowSimilar(b *testing.B) {
s1 := "Hugo is cool and " + strings.Repeat("fun ", 10) + "!"
s2 := "Hugo is cool and " + strings.Repeat("cool ", 10) + "!"