-
Notifications
You must be signed in to change notification settings - Fork 0
/
cwl_test.go
42 lines (37 loc) · 783 Bytes
/
cwl_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
package nlm
import (
"testing"
)
func TestCountWeightedList(t *testing.T) {
tests := []map[rune]int{
{'a': 1},
{'a': 1, 'b': 1, 'c': 1},
{'a': 10},
{'a': 10, 'b': 5, 'c': 5},
{'a': 1, 'b': 4, 'c': 0},
{'a': 0, 'b': 0, 'c': 1},
{'a': 0, 'b': 0, 'c': 5},
{'a': 0, 'b': 5, 'c': 0},
}
for _, test := range tests {
cwl := NewCountWeightedList(test)
r := cwl.GetRandomItem()
if test[r] <= 0 {
t.Errorf("For %#v: got %d which is not in the list", test, r)
}
}
}
func TestEmptyCountWeightedList(t *testing.T) {
tests := []map[rune]int{
{},
{'a': 0},
{'a': 0, 'b': 0, 'c': 0},
}
for _, test := range tests {
cwl := NewCountWeightedList(test)
r := cwl.GetRandomItem()
if r != 0 {
t.Errorf("For %#v: expected 0, got %d", test, r)
}
}
}