use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.
the class AbstractCheckpointCollectionTest method testInsert.
/**
* Test a single insertion
*/
@Test
public void testInsert() {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L), 0);
fCheckpointCollection.insert(checkpoint);
long found = fCheckpointCollection.binarySearch(checkpoint);
assertEquals(0, found);
assertEquals(1, fCheckpointCollection.size());
}
use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.
the class AbstractCheckpointCollectionTest method testGetSize.
/**
* Test get size
*/
@Test
public void testGetSize() {
assertEquals(0, fCheckpointCollection.size());
int expected = CHECKPOINTS_INSERT_NUM;
for (int i = 0; i < expected; ++i) {
fCheckpointCollection.insert(new TmfCheckpoint(TmfTimestamp.fromSeconds(i), new TmfLongLocation(i), i));
}
assertEquals(expected, fCheckpointCollection.size());
}
use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.
the class AbstractCheckpointCollectionTest method testInsertSameTimestamp.
/**
* Test many checkpoint insertions using the same timestamp. Make sure they
* can be found after re-opening the file
*/
@Test
public void testInsertSameTimestamp() {
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L + i), i);
fCheckpointCollection.insert(checkpoint);
}
assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
if (isPersistableCollection()) {
fCheckpointCollection.dispose();
}
boolean random = true;
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
if (random) {
Random rand = new Random();
list.add(rand.nextInt(CHECKPOINTS_INSERT_NUM));
} else {
list.add(i);
}
}
if (isPersistableCollection()) {
fCheckpointCollection = createCollection();
}
assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
Integer randomCheckpoint = list.get(i);
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345), new TmfLongLocation(123456L + randomCheckpoint), 0);
long found = fCheckpointCollection.binarySearch(checkpoint);
assertEquals(randomCheckpoint.intValue(), found);
}
}
use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.
the class AbstractCheckpointCollectionTest method testBinarySearchFindInBetween.
/**
* Tests that binarySearch find the correct checkpoint when the time stamp
* is between checkpoints
*/
@Test
public void testBinarySearchFindInBetween() {
for (long i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(2 * i), new TmfLongLocation(2 * i), i);
fCheckpointCollection.insert(checkpoint);
}
assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
TmfCheckpoint searchedCheckpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(123), new TmfLongLocation(123L), 123);
int expectedInsertionPoint = 61;
int expectedRank = -(expectedInsertionPoint + 2);
long rank = fCheckpointCollection.binarySearch(searchedCheckpoint);
assertEquals(expectedRank, rank);
}
use of org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation in project tracecompass by tracecompass.
the class AbstractCheckpointCollectionTest method insertAlot.
/**
* Generate many checkpoints and insert them in the collection
*
* @return the list of generated checkpoints
*/
protected ArrayList<Integer> insertAlot() {
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
TmfCheckpoint checkpoint = new TmfCheckpoint(TmfTimestamp.fromSeconds(12345 + i), new TmfLongLocation(123456L + i), i);
fCheckpointCollection.insert(checkpoint);
}
assertEquals(CHECKPOINTS_INSERT_NUM, fCheckpointCollection.size());
if (isPersistableCollection()) {
fCheckpointCollection.dispose();
}
boolean random = true;
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < CHECKPOINTS_INSERT_NUM; i++) {
if (random) {
Random rand = new Random();
list.add(rand.nextInt(CHECKPOINTS_INSERT_NUM));
} else {
list.add(i);
}
}
return list;
}
Aggregations