@@ -37,8 +37,10 @@ public class TestSampleQuantiles {
37
37
new Quantile (0.95 , 0.005 ), new Quantile (0.99 , 0.001 ) };
38
38
39
39
SampleQuantiles estimator ;
40
+ Random rnd = new Random (0xDEADDEAD );
41
+ final static int NUM_REPEATS = 10 ;
40
42
41
- @ Before
43
+ @ Before
42
44
public void init () {
43
45
estimator = new SampleQuantiles (quantiles );
44
46
}
@@ -92,22 +94,21 @@ public void testClear() throws IOException {
92
94
@ Test
93
95
public void testQuantileError () throws IOException {
94
96
final int count = 100000 ;
95
- Random r = new Random (0xDEADDEAD );
96
97
int [] values = new int [count ];
97
98
for (int i = 0 ; i < count ; i ++) {
98
99
values [i ] = i + 1 ;
99
100
}
100
101
101
- // Do 10 shuffle/insert/check cycles
102
- for (int i = 0 ; i < 10 ; i ++) {
102
+ // Repeat shuffle/insert/check cycles 10 times
103
+ for (int i = 0 ; i < NUM_REPEATS ; i ++) {
103
104
104
105
// Shuffle
105
- Collections .shuffle (Arrays .asList (values ), r );
106
+ Collections .shuffle (Arrays .asList (values ), rnd );
106
107
estimator .clear ();
107
108
108
109
// Insert
109
- for (int j = 0 ; j < count ; j ++ ) {
110
- estimator .insert (values [ j ] );
110
+ for (int value : values ) {
111
+ estimator .insert (value );
111
112
}
112
113
Map <Quantile , Long > snapshot ;
113
114
snapshot = estimator .snapshot ();
@@ -131,21 +132,20 @@ public void testQuantileError() throws IOException {
131
132
public void testInverseQuantiles () throws IOException {
132
133
SampleQuantiles inverseQuantilesEstimator = new SampleQuantiles (MutableInverseQuantiles .INVERSE_QUANTILES );
133
134
final int count = 100000 ;
134
- Random r = new Random (0xDEADDEAD );
135
135
int [] values = new int [count ];
136
136
for (int i = 0 ; i < count ; i ++) {
137
137
values [i ] = i + 1 ;
138
138
}
139
139
140
- // Do 10 shuffle/insert/check cycles
141
- for (int i = 0 ; i < 10 ; i ++) {
140
+ // Repeat shuffle/insert/check cycles 10 times
141
+ for (int i = 0 ; i < NUM_REPEATS ; i ++) {
142
142
// Shuffle
143
- Collections .shuffle (Arrays .asList (values ), r );
143
+ Collections .shuffle (Arrays .asList (values ), rnd );
144
144
inverseQuantilesEstimator .clear ();
145
145
146
146
// Insert
147
- for (int j = 0 ; j < count ; j ++ ) {
148
- inverseQuantilesEstimator .insert (values [ j ] );
147
+ for (int value : values ) {
148
+ inverseQuantilesEstimator .insert (value );
149
149
}
150
150
Map <Quantile , Long > snapshot ;
151
151
snapshot = inverseQuantilesEstimator .snapshot ();
0 commit comments