When comparing my solution to other submissions, I have noticed a discrepancy in the answers, which led me to believe that the test doesn’t assure correct understanding and implementation of rand.Intn()
boundary.
Accepted solutions would include anything with a value under 20, which is not what we want. An example of a wrong solution: Rlyehan's solution for Animal Magic in Go on Exercism
I would suggest updating the test to something like this, but I am not 100% sure how to achieve determinism other than by increasing the number of tests. I am sure there is a way of doing that in go, but I am too new to it.
func TestRollADie(t *testing.T) {
const tests = 100
seen := make(map[int]bool)
for i := 0; i < tests; i++ {
got := RollADie()
if got < 1 || got > 20 {
t.Fatalf("RollADie() out of range: %d", got)
}
seen[got] = true
}
if len(seen) != 20 {
t.Errorf("Not all sides of the die appeared. Seen sides: %v", seen)
}
}