-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...core/src/test/java/com/the_qa_company/qendpoint/core/util/disk/AbstractLongArrayTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.the_qa_company.qendpoint.core.util.disk; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Random; | ||
|
||
public class AbstractLongArrayTest { | ||
|
||
@Test | ||
public void updateEstimatedLocationArrayBucketSize() { | ||
|
||
Random random = new Random(); | ||
AbstractLongArray longArray = new AbstractLongArray() { | ||
@Override | ||
public long get(long index) { | ||
return Math.max(0, maxValue - index); | ||
} | ||
|
||
@Override | ||
public long length() { | ||
return AbstractLongArray.ESTIMATED_LOCATION_ARRAY_SIZE * 1024L; | ||
} | ||
|
||
@Override | ||
public int sizeOf() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void resize(long newSize) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public void clear() { | ||
|
||
} | ||
|
||
@Override | ||
protected void innerSet(long index, long value) { | ||
|
||
} | ||
}; | ||
|
||
longArray.getEstimatedLocation(Long.MAX_VALUE, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(Long.MAX_VALUE); | ||
longArray.getEstimatedLocationUpperBound(Long.MAX_VALUE); | ||
|
||
longArray.getEstimatedLocation(-1, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(-1); | ||
longArray.getEstimatedLocationUpperBound(-1); | ||
|
||
longArray.getEstimatedLocation(0, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(0); | ||
longArray.getEstimatedLocationUpperBound(0); | ||
|
||
longArray.recalculateEstimatedValueLocation(); | ||
longArray.getEstimatedLocation(Long.MAX_VALUE, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(Long.MAX_VALUE); | ||
longArray.getEstimatedLocationUpperBound(Long.MAX_VALUE); | ||
|
||
longArray.getEstimatedLocation(-1, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(-1); | ||
longArray.getEstimatedLocationUpperBound(-1); | ||
|
||
longArray.getEstimatedLocation(0, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(0); | ||
longArray.getEstimatedLocationUpperBound(0); | ||
|
||
for (long i = 0; i < (AbstractLongArray.ESTIMATED_LOCATION_ARRAY_SIZE * 1024L) + 3; i++) { | ||
testMaxValue(longArray, i); | ||
} | ||
|
||
longArray.recalculateEstimatedValueLocation(); | ||
|
||
for (long i = 1; i > 0 && i < (Long.MAX_VALUE - 1); i *= 2) { | ||
testMaxValue(longArray, i); | ||
} | ||
|
||
longArray.recalculateEstimatedValueLocation(); | ||
|
||
testMaxValue(longArray, Long.MAX_VALUE); | ||
System.out.println(); | ||
|
||
longArray.recalculateEstimatedValueLocation(); | ||
|
||
long estimatedLocation = longArray.getEstimatedLocation(Long.MAX_VALUE, -1, Long.MAX_VALUE); | ||
long estimatedLocationLowerBound = longArray.getEstimatedLocationLowerBound(Long.MAX_VALUE); | ||
long estimatedLocationUpperBound = longArray.getEstimatedLocationUpperBound(Long.MAX_VALUE); | ||
} | ||
|
||
private static void testMaxValue(AbstractLongArray longArray, long value) { | ||
|
||
longArray.maxValue = value; | ||
|
||
longArray.updateEstimatedLocationArrayBucketSize(); | ||
|
||
long estimatedLocationArrayBucketSize = longArray.getEstimatedLocationArrayBucketSize(); | ||
|
||
Assert.assertTrue(estimatedLocationArrayBucketSize + "", estimatedLocationArrayBucketSize > 0); | ||
|
||
longArray.getEstimatedLocation(value, -1, Long.MAX_VALUE); | ||
longArray.getEstimatedLocationLowerBound(value); | ||
longArray.getEstimatedLocationUpperBound(value); | ||
} | ||
} |