MCPcopy Create free account
hub / github.com/labstack/gommon / TestRandomStringBias

Function TestRandomStringBias

random/random_test.go:41–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestRandomStringBias(t *testing.T) {
42 t.Parallel()
43 const slen = 33
44 const loop = 100000
45
46 counts := make(map[rune]int)
47 var count int64
48
49 for i := 0; i < loop; i++ {
50 s := String(slen, Alphabetic)
51 require.Equal(t, slen, len(s))
52 for _, b := range s {
53 counts[b]++
54 count++
55 }
56 }
57
58 require.Equal(t, len(Alphabetic), len(counts))
59
60 avg := float64(count) / float64(len(counts))
61 for k, n := range counts {
62 diff := float64(n) / avg
63 if diff < 0.95 || diff > 1.05 {
64 t.Errorf("Bias on '%c': expected average %f, got %d", k, avg, n)
65 }
66 }
67}

Callers

nothing calls this directly

Calls 2

StringFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…