@@ -242,18 +242,14 @@ func testEdgeQueryWithGenerator(t *testing.T,
242
242
var indexCaps []Cap
243
243
var indexes []*ShapeIndex
244
244
for i := 0; i < numIndexes; i++ {
245
- // TODO(rsned): Replace with:
246
- // r := rand.New(rand.NewSource(i))
247
- rand.Seed(int64(i))
248
- indexCaps = append(indexCaps, CapFromCenterAngle(randomPoint(), testCapRadius))
245
+ r := rand.New(rand.NewSource(i))
246
+ indexCaps = append(indexCaps, CapFromCenterAngle(randomPoint(r), testCapRadius))
249
247
indexes = append(indexes, NewShapeIndex())
250
248
gen(indexCaps[i], numEdges, indexes[i])
251
249
}
252
250
253
251
for i := 0; i < numQueries; i++ {
254
- // TODO(rsned): Replace with:
255
- // r := rand.New(rand.NewSource(i))
256
- rand.Seed(int64(i))
252
+ r := rand.New(rand.NewSource(i))
257
253
iIndex := randomUniformInt(numIndexes)
258
254
indexCap := indexCaps[iIndex]
259
255
@@ -273,23 +269,23 @@ func testEdgeQueryWithGenerator(t *testing.T,
273
269
// Occasionally we don't set any limit on the number of result edges.
274
270
// (This may return all edges if we also don't set a distance limit.)
275
271
if oneIn(5) {
276
- opts.MaxResults(1 + randomUniformInt(10))
272
+ opts.MaxResults(1 + randomUniformInt(10, r ))
277
273
}
278
274
279
275
// We set a distance limit 1/3 of the time.
280
276
if oneIn(3) {
281
- opts.DistanceLimit(s1.ChordAngleFromAngle(s1.Angle(randomFloat64()) * queryRadius))
277
+ opts.DistanceLimit(s1.ChordAngleFromAngle(s1.Angle(randomFloat64(r )) * queryRadius))
282
278
}
283
279
if oneIn(2) {
284
280
// Choose a maximum error whose logarithm is uniformly distributed over
285
281
// a reasonable range, except that it is sometimes zero.
286
- opts.MaxError(s1.ChordAngleFromAngle(s1.Angle(math.Pow(1e-4, randomFloat64()) * queryRadius.Radians())))
282
+ opts.MaxError(s1.ChordAngleFromAngle(s1.Angle(math.Pow(1e-4, randomFloat64(r )) * queryRadius.Radians())))
287
283
}
288
284
opts.IncludeInteriors(oneIn(2))
289
285
290
286
query := newQueryFunc(indexes[iIndex], opts)
291
287
292
- switch randomUniformInt(4) {
288
+ switch randomUniformInt(4, r ) {
293
289
case 0:
294
290
// Find the edges furthest from a given point.
295
291
point := samplePointFromCap(queryCap)
@@ -299,22 +295,22 @@ func testEdgeQueryWithGenerator(t *testing.T,
299
295
// Find the edges furthest from a given edge.
300
296
a := samplePointFromCap(queryCap)
301
297
b := samplePointFromCap(
302
- CapFromCenterAngle(a, s1.Angle(math.Pow(1e-4, randomFloat64()))*queryRadius))
298
+ CapFromCenterAngle(a, s1.Angle(math.Pow(1e-4, randomFloat64(r )))*queryRadius))
303
299
target := NewMaxDistanceToEdgeTarget(Edge{a, b})
304
300
testFindEdges(target, query)
305
301
306
302
case 2:
307
303
// Find the edges furthest from a given cell.
308
304
minLevel := MaxDiagMetric.MinLevel(queryRadius.Radians())
309
- level := minLevel + randomUniformInt(MaxLevel-minLevel+1)
305
+ level := minLevel + randomUniformInt(MaxLevel-minLevel+1, r )
310
306
a := samplePointFromCap(queryCap)
311
307
cell := CellFromCellID(cellIDFromPoint(a).Parent(level))
312
308
target := NewMaxDistanceToCellTarget(cell)
313
309
testFindEdges(target, query)
314
310
315
311
case 3:
316
312
// Use another one of the pre-built indexes as the target.
317
- jIndex := randomUniformInt(numIndexes)
313
+ jIndex := randomUniformInt(numIndexes, r )
318
314
target := NewMaxDistanceToShapeIndexTarget(indexes[jIndex])
319
315
target.setIncludeInteriors(oneIn(2))
320
316
testFindEdges(target, query)
@@ -438,9 +434,9 @@ func generateEdgeQueryWithTargets(opts *edgeQueryBenchmarkOptions, query *EdgeQu
438
434
439
435
// Set a specific seed to allow repeatability
440
436
// Replace with r := rand.New(rand.NewSource(opts.randomSeed)) and pass through.
441
- rand .Seed ( opts .randomSeed )
437
+ r := rand .New ( rand . NewSource ( opts .randomSeed ) )
442
438
opts .randomSeed ++
443
- indexCap := CapFromCenterAngle (randomPoint (), opts .radiusKm )
439
+ indexCap := CapFromCenterAngle (randomPoint (r ), opts .radiusKm )
444
440
445
441
query .Reset ()
446
442
queryIndex .Reset ()
0 commit comments