From 5218756b4620e402fda908c8ff3233a7d87bd0d2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 19 Jul 2023 12:04:34 +0200 Subject: [PATCH] review --- util/bpmath/bp.go | 4 ++-- util/bpmath/bp_test.go | 2 +- util/bpmath/fixed_bp.go | 2 +- util/bpmath/fixed_bp_test.go | 24 ++++++++++++------------ util/bpmath/types.go | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/util/bpmath/bp.go b/util/bpmath/bp.go index f0f5c1c545..fc1c9fe267 100644 --- a/util/bpmath/bp.go +++ b/util/bpmath/bp.go @@ -21,7 +21,7 @@ func quo(a, b cmath.Int, rounding Rounding, max uint64) uint64 { if b.IsZero() { panic("divider can't be zero") } - bp := a.MulRaw(ONE) + bp := a.MulRaw(One) if rounding == UP { bp = bp.Add(b.SubRaw(1)) } @@ -38,7 +38,7 @@ func Mul[T BP | FixedBP](a cmath.Int, b T) cmath.Int { if b == 0 { return cmath.ZeroInt() } - if b == ONE { + if b == One { return a } return a.MulRaw(int64(b)).Quo(oneBigInt) diff --git a/util/bpmath/bp_test.go b/util/bpmath/bp_test.go index fd03b81fbd..13063b405a 100644 --- a/util/bpmath/bp_test.go +++ b/util/bpmath/bp_test.go @@ -16,7 +16,7 @@ func TestBPToDec(t *testing.T) { exp math.LegacyDec }{ {"t1", 99999, math.LegacyMustNewDecFromStr("9.9999")}, - {"t2", ONE * 10, math.LegacyMustNewDecFromStr("10.0")}, + {"t2", One * 10, math.LegacyMustNewDecFromStr("10.0")}, } require := require.New(t) for _, tc := range tcs { diff --git a/util/bpmath/fixed_bp.go b/util/bpmath/fixed_bp.go index b8b993dc8b..79f4cec550 100644 --- a/util/bpmath/fixed_bp.go +++ b/util/bpmath/fixed_bp.go @@ -12,7 +12,7 @@ type FixedBP uint32 // Contract: a>=0 and b > 0. // Panics if b==0. func FixedFromQuo(dividend, divisor math.Int, rounding Rounding) FixedBP { - return FixedBP(quo(dividend, divisor, rounding, ONE)) + return FixedBP(quo(dividend, divisor, rounding, One)) } func (bp FixedBP) ToDec() math.LegacyDec { diff --git a/util/bpmath/fixed_bp_test.go b/util/bpmath/fixed_bp_test.go index 5f5beb8185..6d0b4b9208 100644 --- a/util/bpmath/fixed_bp_test.go +++ b/util/bpmath/fixed_bp_test.go @@ -18,18 +18,18 @@ func TestFixedQuo(t *testing.T) { exp FixedBP panics bool }{ - {"t1", 0, 0, UP, ONE, true}, - {"t2", 0, 0, DOWN, ONE, true}, - {"t3", 1, 0, UP, ONE, true}, - {"t4", 1, 0, DOWN, ONE, true}, + {"t1", 0, 0, UP, One, true}, + {"t2", 0, 0, DOWN, One, true}, + {"t3", 1, 0, UP, One, true}, + {"t4", 1, 0, DOWN, One, true}, {"t5", 20, 10, UP, 0, true}, {"t6", 20, 10, DOWN, 0, true}, - {"t7", 20, 20, UP, ONE, false}, - {"t7-1", 20, 20, DOWN, ONE, false}, + {"t7", 20, 20, UP, One, false}, + {"t7-1", 20, 20, DOWN, One, false}, - {"t8", 1, 2, UP, ONE / 2, false}, - {"t9", 1, 2, DOWN, ONE / 2, false}, + {"t8", 1, 2, UP, One / 2, false}, + {"t9", 1, 2, DOWN, One / 2, false}, {"t10", 1, 3, UP, 3334, false}, {"t11", 1, 3, DOWN, 3333, false}, {"t12", 2, 3, UP, 6667, false}, @@ -63,14 +63,14 @@ func TestFixedMul(t *testing.T) { }{ {"t1", 20, 0, 0}, {"t2", 20, 1, 0}, - {"t3", 20, ONE, 20}, + {"t3", 20, One, 20}, {"t4", 20000, 0, 0}, {"t5", 20000, 1, 2}, {"t6", 20000, 2, 4}, - {"t7", 20000, half, 10000}, + {"t7", 20000, Half, 10000}, {"t8", 2000, 4, 0}, {"t9", 2000, 5, 1}, - {"t10", 2000, half, 1000}, + {"t10", 2000, Half, 1000}, } require := require.New(t) for _, tc := range tcs { @@ -96,7 +96,7 @@ func TestFixedToDec(t *testing.T) { {"t2", 1, math.LegacyMustNewDecFromStr("0.0001")}, {"t3", 20, math.LegacyMustNewDecFromStr("0.002")}, {"t4", 9999, math.LegacyMustNewDecFromStr("0.9999")}, - {"t5", ONE, math.LegacyNewDec(1)}, + {"t5", One, math.LegacyNewDec(1)}, } require := require.New(t) for _, tc := range tcs { diff --git a/util/bpmath/types.go b/util/bpmath/types.go index fa8fc65ac4..705a75b13c 100644 --- a/util/bpmath/types.go +++ b/util/bpmath/types.go @@ -12,8 +12,8 @@ const ( ) const One = 10000 -const half = ONE / 2 +const Half = One / 2 var ( - oneBigInt = math.NewIntFromUint64(ONE) + oneBigInt = math.NewIntFromUint64(One) )