Skip to content

Commit 276d673

Browse files
author
lrhodes
committed
Make random tests deterministic.
1 parent 0ba1c2b commit 276d673

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/test/java/com/yahoo/sketches/tuple/FilterTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.yahoo.sketches.tuple;
22

3+
import java.util.Random;
4+
35
import org.testng.Assert;
46
import org.testng.annotations.Test;
57

6-
import java.util.Random;
7-
88
public class FilterTest {
99

10-
private final int numberOfElements = 100;
10+
private static final int numberOfElements = 100;
11+
private static final Random random = new Random(1);//deterministic for this class
1112

1213
@Test
1314
public void emptySketch() {
@@ -39,7 +40,8 @@ public void nullSketch() {
3940

4041
@Test
4142
public void filledSketchShouldBehaveTheSame() {
42-
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
43+
UpdatableSketch<Double, DoubleSummary> sketch =
44+
new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
4345

4446
fillSketch(sketch, numberOfElements, 0.0);
4547

@@ -56,7 +58,8 @@ public void filledSketchShouldBehaveTheSame() {
5658

5759
@Test
5860
public void filledSketchShouldFilterOutElements() {
59-
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
61+
UpdatableSketch<Double, DoubleSummary> sketch =
62+
new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
6063

6164
fillSketch(sketch, numberOfElements, 0.0);
6265
fillSketch(sketch, 2 * numberOfElements, 1.0);
@@ -74,7 +77,8 @@ public void filledSketchShouldFilterOutElements() {
7477

7578
@Test
7679
public void filteringInEstimationMode() {
77-
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
80+
UpdatableSketch<Double, DoubleSummary> sketch =
81+
new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).build();
7882

7983
int n = 10000;
8084
fillSketch(sketch, n, 0.0);
@@ -93,7 +97,9 @@ public void filteringInEstimationMode() {
9397

9498
@Test
9599
public void nonEmptySketchWithNoEntries() {
96-
UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<>(new DoubleSummaryFactory()).setSamplingProbability(0.0001f).build();
100+
UpdatableSketch<Double, DoubleSummary> sketch =
101+
new UpdatableSketchBuilder<>(
102+
new DoubleSummaryFactory()).setSamplingProbability(0.0001f).build();
97103
sketch.update(0, 0.0);
98104

99105
Assert.assertFalse(sketch.isEmpty());
@@ -110,11 +116,12 @@ public void nonEmptySketchWithNoEntries() {
110116
Assert.assertEquals(filteredSketch.getUpperBound(1), sketch.getUpperBound(1));
111117
}
112118

113-
private static void fillSketch(UpdatableSketch<Double, DoubleSummary> sketch, int numberOfElements, Double sketchValue) {
114-
Random random = new Random();
119+
private static void fillSketch(UpdatableSketch<Double, DoubleSummary> sketch,
120+
int numberOfElements, Double sketchValue) {
121+
115122

116-
for (int cont = 0; cont < numberOfElements; cont++) {
117-
sketch.update(random.nextLong(), sketchValue);
118-
}
123+
for (int cont = 0; cont < numberOfElements; cont++) {
124+
sketch.update(random.nextLong(), sketchValue);
125+
}
119126
}
120127
}

0 commit comments

Comments
 (0)