Add tests for WeightedRandomChooser

This commit is contained in:
Deluan
2021-05-28 23:51:56 -04:00
parent dd56a7798e
commit 7bbb09e546
3 changed files with 54 additions and 2 deletions
+3
View File
@@ -29,6 +29,9 @@ func (w *weightedChooser) Put(value interface{}, weight int) {
// GetAndRemove choose a random entry based on their weights, and removes it from the list
func (w *weightedChooser) GetAndRemove() (interface{}, error) {
if w.totalWeight == 0 {
return nil, errors.New("cannot choose from zero weight")
}
i, err := w.weightedChoice()
if err != nil {
return nil, err