Skip to content

Commit fd5dfa8

Browse files
committed
tests: minor refactor, avoid repetition
1 parent 3f0d787 commit fd5dfa8

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

conversion_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,26 +1477,24 @@ func BenchmarkDecimal(b *testing.B) {
14771477
})
14781478
}
14791479

1480+
func testFloat64(t *testing.T, z *Int) {
1481+
bigF, _ := new(big.Float).SetInt(z.ToBig()).Float64()
1482+
_ = z.Float64() // Op must not modify the z
1483+
if have, want := z.Float64(), bigF; have != want {
1484+
t.Errorf("%s: have %f want %f", z.Hex(), have, want)
1485+
}
1486+
}
1487+
14801488
func TestFloat64(t *testing.T) {
14811489
for i := uint(0); i < 255; i++ {
14821490
z := NewInt(1)
1483-
z.Lsh(z, i)
1484-
bigF, _ := new(big.Float).SetInt(z.ToBig()).Float64()
1485-
_ = z.Float64() // Op must not modify the z
1486-
if have, want := z.Float64(), bigF; have != want {
1487-
t.Errorf("%s: have %f want %f", z.Hex(), have, want)
1488-
}
1491+
testFloat64(t, z.Lsh(z, i))
14891492
}
14901493
}
14911494

14921495
func FuzzFloat64(f *testing.F) {
14931496
f.Fuzz(func(t *testing.T, aa, bb, cc, dd uint64) {
1494-
z := &Int{aa, bb, cc, dd}
1495-
bigF, _ := new(big.Float).SetInt(z.ToBig()).Float64()
1496-
_ = z.Float64() // Op must not modify the z
1497-
if have, want := z.Float64(), bigF; have != want {
1498-
t.Errorf("%s: have %f want %f", z.Hex(), have, want)
1499-
}
1497+
testFloat64(t, &Int{aa, bb, cc, dd})
15001498
})
15011499
}
15021500

0 commit comments

Comments
 (0)