positive
This commit is contained in:
parent
10ddc97854
commit
e0ca0be76a
|
@ -28,33 +28,27 @@ public class UUIDPositiveLongGeneratorUnitTest {
|
||||||
|
|
||||||
|
|
||||||
private void printTableHeader() {
|
private void printTableHeader() {
|
||||||
logger.info(String.format("%-30s %-15s %-15s %-15s %-15s", "Approach", "collisions", "negatives", "collision", "negative"));
|
logger.info(String.format("%-30s %-15s %-15s", "Approach(method name)", "collisions", "probability"));
|
||||||
logger.info(String.format("%-30s %-15s %-15s %-15s %-15s", "(method name)", "count", "count", "probability", "probability"));
|
logger.info("-----------------------------------------------------------------------");
|
||||||
logger.info("--------------------------------------------------------------------------------------------");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printOutput(String method, int collisionsCount, int negativeCount, double collisionsProbability, double negativeProbability) {
|
private void printOutput(String method, int collisionsCount, double collisionsProbability) {
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("#.#####");
|
DecimalFormat decimalFormat = new DecimalFormat("#.#####");
|
||||||
logger.info(String.format("%-30s %-15s %-15s %-15s %-15s", method, collisionsCount, negativeCount, decimalFormat.format(collisionsProbability), decimalFormat.format(negativeProbability)));
|
logger.info(String.format("%-30s %-15s %-15s", method, collisionsCount, decimalFormat.format(collisionsProbability)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void collisionCheck(Method method) throws InvocationTargetException, IllegalAccessException {
|
private void collisionCheck(Method method) throws InvocationTargetException, IllegalAccessException {
|
||||||
Set<Long> uniqueValues = new HashSet<>();
|
Set<Long> uniqueValues = new HashSet<>();
|
||||||
int collisions = 0;
|
int collisions = 0;
|
||||||
int negative = 0;
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
long uniqueValue = (long) method.invoke(uuidLongGenerator);
|
long uniqueValue = (long) method.invoke(uuidLongGenerator);
|
||||||
if (!uniqueValues.add(uniqueValue)) {
|
if (!uniqueValues.add(uniqueValue)) {
|
||||||
collisions++;
|
collisions++;
|
||||||
}
|
}
|
||||||
if (uniqueValue < 0) {
|
|
||||||
negative++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
double collisionsProbability = (double) collisions / n;
|
double collisionsProbability = (double) collisions / n;
|
||||||
double negativeProbability = (double) negative / n;
|
printOutput(method.getName(), collisions, collisionsProbability);
|
||||||
printOutput(method.getName(), collisions, negative, collisionsProbability, negativeProbability);
|
|
||||||
assertThat(collisionsProbability).isLessThan(COLLISION_THRESHOLD);
|
assertThat(collisionsProbability).isLessThan(COLLISION_THRESHOLD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue