Refactor random functions
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
package number
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
func RandomInt64(max int64) int64 {
|
||||
rnd, _ := rand.Int(rand.Reader, big.NewInt(max))
|
||||
return rnd.Int64()
|
||||
}
|
||||
|
||||
func ParseInt[T constraints.Integer](s string) T {
|
||||
r, _ := strconv.ParseInt(s, 10, 64)
|
||||
return T(r)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/navidrome/navidrome/utils/number"
|
||||
"github.com/navidrome/navidrome/utils/random"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ var _ = Describe("number package", func() {
|
||||
Describe("RandomInt64", func() {
|
||||
It("should return a random int64", func() {
|
||||
for i := 0; i < 10000; i++ {
|
||||
Expect(number.RandomInt64(100)).To(BeNumerically("<", 100))
|
||||
Expect(random.Int64(100)).To(BeNumerically("<", 100))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user