Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jan 27, 2018
1 parent e5d998d commit a6144a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/test/java/gr/james/sampling/ChaoSamplingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChaoSamplingTest {
private static final int REPS = 10000000;

/**
* In {@link ChaoSampling} the appearance probability must be proportional to the item weight
* In {@link ChaoSampling} the appearance probability must be proportional to the item weight.
*/
@Test
public void correctness() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/gr/james/sampling/RandomSamplingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.stream.IntStream;

/**
* Tests for unweighted algorithms (and weighted used as unweighted)
* Tests for unweighted algorithms (and weighted used as unweighted).
*/
@RunWith(Parameterized.class)
public class RandomSamplingTest {
Expand Down Expand Up @@ -41,7 +41,7 @@ public static Collection<Supplier<RandomSampling<Integer>>> implementations() {
}

/**
* All items must be selected with equal probability
* All items must be selected with equal probability.
*/
@Test
public void correctness() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.stream.IntStream;

/**
* Tests for weighted algorithms
* Tests for weighted algorithms.
*/
@RunWith(Parameterized.class)
public class WeightedRandomSamplingTest {
Expand All @@ -39,20 +39,24 @@ public static Collection<Supplier<WeightedRandomSampling<Integer>>> implementati
}

/**
* Increased weight means more occurrences
* Increased weight means more occurrences.
*/
@Test
public void correctness() {
final int[] d = new int[STREAM];

for (int reps = 0; reps < REPS; reps++) {
final WeightedRandomSampling<Integer> alg = impl.get();

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

for (int s : alg.sample()) {
d[s]++;
}
}

for (int i = 0; i < d.length - 1; i++) {
Assert.assertTrue("WeightedRandomSamplingTest.correctness", d[i] < d[i + 1]);
}
Expand Down

0 comments on commit a6144a7

Please sign in to comment.