removed duplicated code thanks to slicex

This commit is contained in:
pippellia-btc
2025-06-23 18:55:15 +02:00
parent 8f630f0bfb
commit b637e35991
10 changed files with 62 additions and 165 deletions

View File

@@ -5,6 +5,7 @@ import (
"math/rand/v2"
"testing"
"github.com/pippellia-btc/slicex"
"github.com/vertex-lab/crawler_v2/pkg/pagerank"
"github.com/vertex-lab/crawler_v2/pkg/walks"
)
@@ -88,7 +89,7 @@ func TestPagerankDynamic(t *testing.T) {
store := NewWalkStore()
// apply a random delta to the graph
delta := randomElement(test.deltas)
delta := slicex.RandomElement(test.deltas)
test.walker.Update(ctx, delta)
rwalks, err := walks.Generate(ctx, test.walker, test.nodes...)
@@ -172,8 +173,3 @@ func TestPersonalized(t *testing.T) {
})
}
}
// returns a random element of a slice. It panics if the slice is empty or nil.
func randomElement[S []E, E any](s S) E {
return s[rand.IntN(len(s))]
}