chore: optimize coding style and add unit tests (#3917)

master
Kevin Wan 9 months ago committed by GitHub
parent 28cb2c5804
commit 6be37ad533
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -15,3 +15,17 @@ func TestCalcEntropy(t *testing.T) {
} }
assert.True(t, CalcEntropy(m) > .99) assert.True(t, CalcEntropy(m) > .99)
} }
func TestCalcEmptyEntropy(t *testing.T) {
m := make(map[any]int)
assert.Equal(t, float64(1), CalcEntropy(m))
}
func TestCalcDiffEntropy(t *testing.T) {
const total = 1000
m := make(map[any]int, total)
for i := 0; i < total; i++ {
m[i] = i
}
assert.True(t, CalcEntropy(m) < .99)
}

@ -172,6 +172,7 @@ func TestTimeoutSSE(t *testing.T) {
handler.ServeHTTP(resp, req) handler.ServeHTTP(resp, req)
assert.Equal(t, http.StatusOK, resp.Code) assert.Equal(t, http.StatusOK, resp.Code)
} }
func TestTimeoutWebsocket(t *testing.T) { func TestTimeoutWebsocket(t *testing.T) {
timeoutHandler := TimeoutHandler(time.Millisecond) timeoutHandler := TimeoutHandler(time.Millisecond)
handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handler := timeoutHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save