26 lines
395 B
Go
26 lines
395 B
Go
package xrand
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestWeightRandom(t *testing.T) {
|
|
stat := make(map[any]int)
|
|
for i := 1; i <= 10000; i++ {
|
|
items := map[uint]string{
|
|
5: "a",
|
|
15: "b",
|
|
30: "c",
|
|
50: "d",
|
|
}
|
|
item, err := WeightRandom(items)
|
|
assert.Nil(t, err)
|
|
if _, ok := stat[item]; !ok {
|
|
stat[item] = 0
|
|
}
|
|
stat[item]++
|
|
}
|
|
t.Log(stat)
|
|
}
|