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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.predicate.index.conjunction;
import com.yahoo.search.predicate.SubqueryBitmap;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author bjorncs
*/
public class ConjunctionIdIteratorTest {
@SuppressWarnings("PointlessBitwiseExpression")
@Test
public void require_that_next_returns_skips_to_correct_value() {
// NOTE: LST bit represents the conjunction sign: 0 => negative, 1 => positive.
int[] conjunctionIds = new int[]{
0 | 1,
2 | 0,
4 | 0,
6 | 1,
8 | 1,
10 | 0};
ConjunctionIdIterator postingList =
new ConjunctionIdIterator(SubqueryBitmap.ALL_SUBQUERIES, conjunctionIds);
assertEquals(1, postingList.getConjunctionId());
assertEquals(1, postingList.getConjunctionId()); // Should not change.
assertTrue(postingList.next(2));
assertEquals(2, postingList.getConjunctionId());
assertTrue(postingList.next(0)); // Should not change current conjunction id
assertEquals(2, postingList.getConjunctionId());
assertTrue(postingList.next(6 | 1)); // Should skip past id 4
assertEquals(7, postingList.getConjunctionId());
assertTrue(postingList.next(8)); // Should skip to 9
assertEquals(9, postingList.getConjunctionId());
assertTrue(postingList.next(10 | 1));
assertEquals(10, postingList.getConjunctionId());
assertFalse(postingList.next(12)); // End of posting list
}
@Test
public void require_that_subquery_is_correct() {
ConjunctionIdIterator iterator = new ConjunctionIdIterator(0b1111, new int[]{1});
assertEquals(0b1111, iterator.getSubqueryBitmap());
}
}
|