Files
gonum/graph/set/uid/uid_test.go
Dan Kortschak cf3307fa63 all: partially migrate to math/rand/v2
This is not intended to be a completed transition since it leaves the
libraries unusable to external client code, but rather as a step towards
use of math/rand/v2. This initial step allows repair of sequence change
failures without having to worry about API difference.
2025-02-01 22:18:04 +10:30

48 lines
945 B
Go

// Copyright ©2020 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package uid implements unique ID provision for graphs.
package uid
import (
"math"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
func TestSetChurn(t *testing.T) {
rnd := rand.New(rand.NewSource(1))
set := NewSet()
// Iterate over a number of ID allocations,
// occasionally deleting IDs from the store.
seen := make(map[int64]bool)
for k := 0; k < 2; k++ {
for i := 0; i < 1e4; i++ {
id := set.NewID()
if seen[id] {
t.Fatalf("NewID returned already used ID")
}
set.Use(id)
seen[id] = true
if rnd.Float64() < 0.01 {
j := rnd.Intn(10)
for id := range seen {
set.Release(id)
delete(seen, id)
j--
if j <= 0 {
break
}
}
}
}
// Kick the set into scavenging mode.
set.Use(math.MaxInt64)
}
}