Skip to content

Commit

Permalink
simplify power of 2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Mar 19, 2015
1 parent 09f9cac commit 2b497e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions settings_header_hash_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ func (h *HTTPHeaderHashFilters) Set(value string) error {
panic("need positive numerators and denominators, with the former less than the latter.")
}

for test := den; test != 1; test /= 2 {
if test%2 == 1 {
return errors.New("must have a denominator which is a power of two.")
}
if den & (den - 1) != 0 {
return errors.New("must have a denominator which is a power of two.")
}

var f headerHashFilter
Expand Down
5 changes: 5 additions & 0 deletions settings_header_hash_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func TestHTTPHeaderHashFilters(t *testing.T) {
t.Error("Should error on HeaderIrrelevant:1/3")
}

err = filters.Set("Pow2Denom:1/31")
if err == nil {
t.Error("Should error on Pow2Denom:1/31")
}

req := http.Request{}
req.Header = make(map[string][]string)
req.Header.Add("Header1", "test3414")
Expand Down

0 comments on commit 2b497e6

Please sign in to comment.