Skip to content

Commit

Permalink
Fix default weight per implementation on tests (gstamatelat#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jul 23, 2020
1 parent eb00d03 commit 9bf3932
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/test/java/gr/james/sampling/WeightedRandomSamplingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Collection<Supplier<WeightedRandomSampling<Integer>>> implementati
@Test
public void correctness() {
final int[] streamSizes = {1, 20, 100};
final int[] repsSizes = {1000000, 1000000, 2000000};
final int[] repsSizes = {1000000, 2000000, 4000000};

Assert.assertEquals(streamSizes.length, repsSizes.length);

Expand All @@ -55,7 +55,7 @@ public void correctness() {
final WeightedRandomSampling<Integer> alg = impl.get();

for (int i = 0; i < STREAM; i++) {
alg.feed(i, i + 1);
alg.feed(i, (i + 1.0) / (STREAM + 1.0));
}

for (int s : alg.sample()) {
Expand All @@ -64,7 +64,10 @@ public void correctness() {
}

for (int i = 0; i < d.length - 1; i++) {
Assert.assertTrue(d[i] < d[i + 1]);
if (d[i] > d[i + 1]) {
System.out.println();
}
Assert.assertTrue(String.format("Correctness failed at stream size %d", STREAM), d[i] < d[i + 1]);
}
}
}
Expand Down Expand Up @@ -96,7 +99,7 @@ public void stream20() {
}

final Collection<Integer> sample = IntStream.range(0, STREAM).boxed()
.collect(Collectors.toMap(o -> o, o -> (double) (o + 1)))
.collect(Collectors.toMap(o -> o, o -> (o + 1.0) / (STREAM + 1.0)))
.entrySet().stream().collect(collector);

for (int s : sample) {
Expand Down Expand Up @@ -131,8 +134,8 @@ public void feedAlternative() {
final WeightedRandomSampling<Integer> rs3 = impl.get();
final Map<Integer, Double> map = new HashMap<>();
for (int i = 1; i <= SAMPLE; i++) {
map.put(i, (double) i);
rs1.feed(i, (double) i);
map.put(i, i / (SAMPLE + 1.0));
rs1.feed(i, i / (SAMPLE + 1.0));
}
rs3.feed(map.keySet().iterator(), map.values().iterator());
rs2.feed(map);
Expand Down

0 comments on commit 9bf3932

Please sign in to comment.