use of io.questdb.std.LongList in project questdb by bluestreak01.
the class IntervalUtilsTest method testIntersectRandomInplaceVsNonInplace.
@Test
public void testIntersectRandomInplaceVsNonInplace() {
long seed = System.currentTimeMillis();
Random r = new Random(seed);
LongList intervals = new LongList();
int aSize = r.nextInt(100) + 10;
int bSize = r.nextInt(100);
long aPos = r.nextInt(1000) - r.nextInt(1000);
long bPos = r.nextInt(1000) - r.nextInt(1000);
// A
for (int i = 0; i < aSize; i++) {
add(intervals, aPos, aPos += r.nextInt(100));
aPos += r.nextInt(100);
}
// B
LongList bItervals = new LongList();
for (int i = 0; i < bSize; i++) {
add(bItervals, bPos, bPos += r.nextInt(100));
bPos += r.nextInt(100);
}
LongList expected = new LongList();
// non-in place algo, supposed to be correct
intersect(intervals, bItervals, expected);
String expectedStr = toIntervalString(expected, 0);
intervals.add(bItervals);
runTestIntersectInplace(intervals, aSize * 2, expectedStr);
}
use of io.questdb.std.LongList in project questdb by bluestreak01.
the class IntervalUtilsTest method testUnionInplaceSimple2.
@Test
public void testUnionInplaceSimple2() {
LongList intervals = new LongList();
// A
add(intervals, -1, 1);
add(intervals, 2, 3);
// B
add(intervals, 1, 2);
add(intervals, 3, 4);
add(intervals, 6, 7);
runTestUnionInplace(intervals, 4, "[-1,4], [6,7]");
}
use of io.questdb.std.LongList in project questdb by bluestreak01.
the class IntervalUtilsTest method testIntersectInplaceLong.
@Test
public void testIntersectInplaceLong() {
LongList intervals = new LongList();
// A
add(intervals, -1, 10);
add(intervals, 12, 13);
// B
add(intervals, 1, 2);
add(intervals, 4, 5);
add(intervals, 7, 7);
add(intervals, 9, 12);
runTestIntersectInplace(intervals, 4, "[1,2], [4,5], [7,7], [9,10], [12,12]");
}
use of io.questdb.std.LongList in project questdb by bluestreak01.
the class IntervalUtilsTest method testIntersectInplace3.
@Test
public void testIntersectInplace3() {
LongList intervals = new LongList();
// A
add(intervals, -5, -3);
add(intervals, -1, 10);
add(intervals, 12, 13);
// B
add(intervals, -20, -10);
add(intervals, 1, 2);
add(intervals, 4, 5);
add(intervals, 7, 7);
add(intervals, 9, 12);
runTestIntersectInplace(intervals, 6, "[1,2], [4,5], [7,7], [9,10], [12,12]");
}
use of io.questdb.std.LongList in project questdb by bluestreak01.
the class IntervalUtilsTest method runTestUnionInplace.
private void runTestUnionInplace(LongList intervals, int divider, String expected) {
LongList copy = new LongList();
copy.add(intervals, divider, intervals.size());
copy.add(intervals, 0, divider);
IntervalUtils.unionInplace(intervals, divider);
TestUtils.assertEquals(expected, toIntervalString(intervals, 0));
IntervalUtils.unionInplace(copy, copy.size() - divider);
TestUtils.assertEquals(expected, toIntervalString(copy, 0));
}
Aggregations