MCPcopy
hub / github.com/labstack/echo / TestRandomStringBias

Function TestRandomStringBias

middleware/util_test.go:77–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestRandomStringBias(t *testing.T) {
78 t.Parallel()
79 const slen = 33
80 const loop = 100000
81
82 counts := make(map[rune]int)
83 var count int64
84
85 for range loop {
86 s := randomString(slen)
87 require.Equal(t, slen, len(s))
88 for _, b := range s {
89 counts[b]++
90 count++
91 }
92 }
93
94 require.Equal(t, randomStringCharsetLen, len(counts))
95
96 avg := float64(count) / float64(len(counts))
97 for k, n := range counts {
98 diff := float64(n) / avg
99 if diff < 0.95 || diff > 1.05 {
100 t.Errorf("Bias on '%c': expected average %f, got %d", k, avg, n)
101 }
102 }
103}
104
105func TestValidateOrigins(t *testing.T) {
106 var testCases = []struct {

Callers

nothing calls this directly

Calls 1

randomStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…