Make TestCounterAddLarge more robust

The previous `float64(math.MaxUint64 + 1)` is too close to
`float64(math.MaxUint64)` to actually overflow as indended.

The counter code is actually converting forward and backward and
compare the original and twice-converted value. On most platform, this
will create a deviation and thus trigger the expected behavior. By
sheer "luck", one might end up with the same value and thus still use
the uint64 representation. Which is OK within the precision we can
expect. But it breaks the test. With this change, the next
representable floating point value greater than the floating point
value used to represent math.MaxUint64 is used.

Signed-off-by: Bjoern Rabenstein <bjoern@rabenste.in>
This commit is contained in:
Bjoern Rabenstein 2019-05-03 22:25:32 +02:00
parent 6aba2189eb
commit bf1f4e4a24
1 changed files with 1 additions and 1 deletions

View File

@ -172,7 +172,7 @@ func TestCounterAddLarge(t *testing.T) {
}).(*counter) }).(*counter)
// large overflows the underlying type and should therefore be stored in valBits. // large overflows the underlying type and should therefore be stored in valBits.
large := float64(math.MaxUint64 + 1) large := math.Nextafter(float64(math.MaxUint64), 1e20)
counter.Add(large) counter.Add(large)
if expected, got := large, math.Float64frombits(counter.valBits); expected != got { if expected, got := large, math.Float64frombits(counter.valBits); expected != got {
t.Errorf("valBits expected %f, got %f.", expected, got) t.Errorf("valBits expected %f, got %f.", expected, got)