Changed tas to spaces

This commit is contained in:
Ziver Koc 2018-05-26 23:01:03 +02:00
parent a938b70d57
commit b1c53d88ae
196 changed files with 14016 additions and 14035 deletions

View file

@ -34,54 +34,54 @@ import java.util.Random;
/**
* This code may be used, modified, and redistributed provided that the
* author tag below remains intact.
*
*
* @author Ian Clarke <ian@uprizer.com>
*/
public class BloomFilterTest extends TestCase {
public void testBloomFilter() {
DecimalFormat df = new DecimalFormat("0.00000");
Random r = new Random(124445l);
int bfSize = 400000;
System.out.println("Testing " + bfSize + " bit SimpleBloomFilter");
for (int i = 5; i < 10; i++) {
int addCount = 10000 * (i + 1);
BloomFilter<Integer> bf = new BloomFilter<Integer>(bfSize, addCount);
HashSet<Integer> added = new HashSet<Integer>();
for (int x = 0; x < addCount; x++) {
int num = r.nextInt();
added.add(num);
}
bf.addAll(added);
assertTrue("Assert that there are no false negatives", bf
.containsAll(added));
public void testBloomFilter() {
DecimalFormat df = new DecimalFormat("0.00000");
Random r = new Random(124445l);
int bfSize = 400000;
System.out.println("Testing " + bfSize + " bit SimpleBloomFilter");
for (int i = 5; i < 10; i++) {
int addCount = 10000 * (i + 1);
BloomFilter<Integer> bf = new BloomFilter<Integer>(bfSize, addCount);
HashSet<Integer> added = new HashSet<Integer>();
for (int x = 0; x < addCount; x++) {
int num = r.nextInt();
added.add(num);
}
bf.addAll(added);
assertTrue("Assert that there are no false negatives", bf
.containsAll(added));
int falsePositives = 0;
for (int x = 0; x < addCount; x++) {
int num = r.nextInt();
int falsePositives = 0;
for (int x = 0; x < addCount; x++) {
int num = r.nextInt();
// Ensure that this random number hasn't been added already
if (added.contains(num)) {
continue;
}
// If necessary, record a false positive
if (bf.contains(num)) {
falsePositives++;
}
}
double expectedFP = bf.falsePositiveProbability();
double actualFP = (double) falsePositives / (double) addCount;
System.out.println("Got " + falsePositives
+ " false positives out of " + addCount + " added items, rate = "
+ df.format(actualFP) + ", expected = "
+ df.format(expectedFP));
double ratio = actualFP/expectedFP;
assertTrue(
"Assert that the actual false positive rate doesn't deviate by more than 10% from what was predicted, ratio: "+ratio,
ratio < 1.1);
}
}
// Ensure that this random number hasn't been added already
if (added.contains(num)) {
continue;
}
// If necessary, record a false positive
if (bf.contains(num)) {
falsePositives++;
}
}
double expectedFP = bf.falsePositiveProbability();
double actualFP = (double) falsePositives / (double) addCount;
System.out.println("Got " + falsePositives
+ " false positives out of " + addCount + " added items, rate = "
+ df.format(actualFP) + ", expected = "
+ df.format(expectedFP));
double ratio = actualFP/expectedFP;
assertTrue(
"Assert that the actual false positive rate doesn't deviate by more than 10% from what was predicted, ratio: "+ratio,
ratio < 1.1);
}
}
}