-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweightedRandom_test.go
60 lines (50 loc) · 971 Bytes
/
weightedRandom_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package weightedRandom
import (
"testing"
)
// ## Example Data
type Elem struct {
ID int
Weight int64
}
func (e Elem) GetWeight() int64 { return e.Weight }
var DummyArray = []Elem{
{ID: 100, Weight: 1},
{ID: 200, Weight: 2},
{ID: 300, Weight: 3},
{ID: 400, Weight: 4},
{ID: 500, Weight: 5},
{ID: 600, Weight: 6},
{ID: 700, Weight: 7},
{ID: 800, Weight: 8},
{ID: 900, Weight: 9},
{ID: 1000, Weight: 10},
}
// ## EXAMPLES
// TODO: Write some examples
// ## TESTS
func TestWeightedRandom(t *testing.T) {
_, err := WeightedRandom(DummyArray)
if err != nil {
t.Fatal(err)
}
}
// ## BENCHMARKS
func BenchmarkWeightedRandom(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := WeightedRandom(DummyArray)
if err != nil {
b.Failed()
}
}
}
func BenchmarkWeightedRandomParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := WeightedRandom(DummyArray)
if err != nil {
b.Failed()
}
}
})
}