MCPcopy Index your code
hub / github.com/perkeep/perkeep / testAroundUnsortedSource

Function testAroundUnsortedSource

pkg/search/query_test.go:1540–1591  ·  view source on GitHub ↗

tests the algorithm for the Around parameter, when the source of blobs is unsorted, i.e. when the blobs get sorted right after the constraint has been matched, and right before Around is applied.

(limit, pos int, t *testing.T)

Source from the content-addressed store, hash-verified

1538// unsorted, i.e. when the blobs get sorted right after the constraint has been
1539// matched, and right before Around is applied.
1540func testAroundUnsortedSource(limit, pos int, t *testing.T) {
1541 testQueryTypes(t, []indexType{indexClassic}, func(qt *queryTest) {
1542 id := qt.id
1543
1544 var sorted []string
1545 unsorted := make(map[string]blob.Ref)
1546
1547 addToSorted := func(i int) {
1548 p := id.NewPlannedPermanode(fmt.Sprintf("%d", i))
1549 unsorted[p.String()] = p
1550 sorted = append(sorted, p.String())
1551 }
1552 for i := 0; i < 10; i++ {
1553 addToSorted(i)
1554 }
1555 sort.Strings(sorted)
1556
1557 // Predict the results
1558 var want []blob.Ref
1559 var around blob.Ref
1560 lowLimit := pos - limit/2
1561 if lowLimit < 0 {
1562 lowLimit = 0
1563 }
1564 highLimit := lowLimit + limit
1565 if highLimit > len(sorted) {
1566 highLimit = len(sorted)
1567 }
1568 // Make the permanodes actually exist.
1569 for k, v := range sorted {
1570 pn := unsorted[v]
1571 id.AddAttribute(pn, "x", "x")
1572 if k == pos {
1573 around = pn
1574 }
1575 if k >= lowLimit && k < highLimit {
1576 want = append(want, pn)
1577 }
1578 }
1579
1580 sq := &SearchQuery{
1581 Constraint: &Constraint{
1582 Permanode: &PermanodeConstraint{},
1583 },
1584 Limit: limit,
1585 Around: around,
1586 Sort: BlobRefAsc,
1587 }
1588 qt.wantRes(sq, want...)
1589 })
1590
1591}
1592
1593func TestQueryAroundCenter(t *testing.T) {
1594 testAroundUnsortedSource(4, 4, t)

Callers 3

TestQueryAroundCenterFunction · 0.85
TestQueryAroundNearFunction · 0.85
TestQueryAroundFarFunction · 0.85

Calls 5

testQueryTypesFunction · 0.85
NewPlannedPermanodeMethod · 0.80
AddAttributeMethod · 0.80
wantResMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected