Commit fa74be44 authored by Fokion Zervoudakis's avatar Fokion Zervoudakis

Rename classes.

parent 6f5a7b87
......@@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.Random;
import java.util.stream.IntStream;
class AlgorithmR {
class ResSampler {
/**
Uses Algorithm R to uniformly select a random element from {@code A} (a.k.a
reservoir sampling).
......@@ -40,7 +40,7 @@ class AlgorithmR {
var A = IntStream.range(0, 10).toArray();
var M = new HashMap<Integer, Double>();
for (var i = 0; i < max; i++) {
var n = AlgorithmR.pick(A);
var n = ResSampler.pick(A);
M.put(n, M.containsKey(n) ? M.get(n) + 1 : 1);
}
for (var E : M.entrySet()) {
......
......@@ -6,18 +6,18 @@ import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
class AlgorithmRTest {
class ResSamplerTest {
@Test
void itDoesNotPickAnythingWithZeroElements() {
var A = new int[0];
AlgorithmR.pick(A);
ResSampler.pick(A);
assertEquals("[]", Arrays.toString(A));
}
@Test
void itPicksOneElement() {
var A = new int[] { 0 };
AlgorithmR.pick(A);
ResSampler.pick(A);
assertEquals("[0]", Arrays.toString(A));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment