aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search/src/test/java/com/yahoo/search/predicate/index/IntervalPostingListTest.java
blob: 755cf39affffb971ed04dfee71fecad6c489f7ef (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.predicate.index;

import com.yahoo.search.predicate.SubqueryBitmap;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.*;

public class IntervalPostingListTest {

    @Test
    void requireThatPostingListCanIterate() {
        PredicateIntervalStore.Builder builder = new PredicateIntervalStore.Builder();
        int ref1 = builder.insert(Arrays.asList(0x1ffff));
        int ref2 = builder.insert(Arrays.asList(0x1ffff));
        int ref3 = builder.insert(Arrays.asList(0x10001, 0x2ffff));
        IntervalPostingList postingList = new IntervalPostingList(
                builder.build(), new int[]{2, 4, 6}, new int[]{ref1, ref2, ref3}, SubqueryBitmap.ALL_SUBQUERIES);
        assertEquals(-1, postingList.getDocId());
        assertEquals(0, postingList.getInterval());
        assertEquals(0xffffffffffffffffL, postingList.getSubquery());

        assertTrue(postingList.nextDocument(0));
        assertTrue(postingList.prepareIntervals());
        assertEquals(2, postingList.getDocId());
        assertEquals(0x1ffff, postingList.getInterval());
        assertFalse(postingList.nextInterval());

        assertTrue(postingList.nextDocument(4));
        assertTrue(postingList.prepareIntervals());
        assertEquals(6, postingList.getDocId());
        assertEquals(0x10001, postingList.getInterval());
        assertTrue(postingList.nextInterval());
        assertEquals(0x2ffff, postingList.getInterval());
        assertFalse(postingList.nextInterval());

        assertFalse(postingList.nextDocument(8));
    }

}