public void test_IteratorFunctionality(GeoRecordBTree grbt) throws IOException { GeoConverter gc = new GeoConverter(); ArrayList<LatitudeLongitudeDocId> lldida = getArrayListLLDID(2); GeoRecord minRecord, maxRecord; minRecord = gc.toGeoRecord((byte) 0, lldida.get(0)); maxRecord = gc.toGeoRecord((byte) 0, lldida.get(1)); GeoUtil gu = new GeoUtil(); if (gu.compare(minRecord, maxRecord) == 1) { minRecord = gc.toGeoRecord((byte) 0, lldida.get(1)); maxRecord = gc.toGeoRecord((byte) 0, lldida.get(0)); } Iterator<GeoRecord> gIt = grbt.getIterator(minRecord, maxRecord); GeoRecord current = null, next = null; while (gIt.hasNext()) { if (next != null) { current = next; } next = gIt.next(); if (current != null) { assertTrue("The indexer is out of order.", gu.compare(current, next) != 1); } assertTrue( "Iterator is out of range ", gu.compare(next, minRecord) != -1 || gu.compare(next, maxRecord) != 1); } }
public void test_CompleteTreeIsOrderedCorrectly(GeoRecordBTree grbt) throws IOException { int len = grbt.arrayLength; for (int index = 0; index < len; index++) { if (index > 0) { if (grbt.isALeftChild(index)) { assertTrue( "Left child incorecctly greater than parent: ", grbt.compareValuesAt(index, grbt.getParentIndex(index)) != 1); } else { assertTrue( "Right child incorecctly less than parent: ", grbt.compareValuesAt(index, grbt.getParentIndex(index)) != -1); } } if (grbt.hasLeftChild(index)) { assertTrue( "Left child incorecctly greater than parent: ", grbt.compareValuesAt(grbt.getLeftChildIndex(index), index) != 1); } else if (grbt.hasRightChild(index)) { assertTrue( "Right child incorecctly less than parent: ", grbt.compareValuesAt(grbt.getRightChildIndex(index), index) != 1); } } }