2020-04-14 11:25:03 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestResults(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
t.Run("SortResultsByScore", func(t *testing.T) {
|
|
|
|
results := []*QueryResult{
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 1,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 3,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 9,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 2,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := []*QueryResult{
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 9,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 3,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 2,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
2020-04-17 17:41:33 +00:00
|
|
|
{
|
2020-04-14 11:25:03 +00:00
|
|
|
File: "/file",
|
|
|
|
Score: 1,
|
|
|
|
FirstMatch: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
sorted := SortResultsByScore(results)
|
|
|
|
|
|
|
|
assert.Equal(expected, sorted, "should be equal")
|
|
|
|
})
|
|
|
|
}
|