Skip to content

Commit

Permalink
Add test fot RandIndex.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bredgren committed Jul 30, 2017
1 parent 233cbaa commit 7d32e89
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,35 @@ func TestMod(t *testing.T) {
}
}
}

func TestRandIndex(t *testing.T) {
cases := [][]float64{
{0.0},
{0.0, 0.0},
{0.0, 0.0, 1.0},
{1.0},
{1.0, 2.0},
{1.0, 4.0},
{1.0, 4.0, 2.0},
{1.5, 2.5},
{-1.0, -1.0},
}

for _, c := range cases {
checkSelectIndexFreq(c)
}
}

func checkSelectIndexFreq(list []float64) {
counts := make(map[int]int)
count := 1000
for i := 0; i < count; i++ {
index := RandIndex(list)
counts[index]++
}

// fmt.Println("Check", list)
// for v, c := range counts {
// fmt.Printf(" %d: %f\n", v, float64(c)/float64(count))
// }
}

0 comments on commit 7d32e89

Please sign in to comment.