allow 'zero y-range delta' (#72)

This commit is contained in:
Edwin 2018-04-16 03:35:39 +08:00 committed by Will Charczuk
parent 7c3982fe3d
commit 2dc8482db3
4 changed files with 8 additions and 22 deletions

View file

@ -93,12 +93,18 @@ func (m mathUtil) GetRoundToForDelta(delta float64) float64 {
// RoundUp rounds up to a given roundTo value.
func (m mathUtil) RoundUp(value, roundTo float64) float64 {
if roundTo < 0.000000000000001 {
return value
}
d1 := math.Ceil(value / roundTo)
return d1 * roundTo
}
// RoundDown rounds down to a given roundTo value.
func (m mathUtil) RoundDown(value, roundTo float64) float64 {
if roundTo < 0.000000000000001 {
return value
}
d1 := math.Floor(value / roundTo)
return d1 * roundTo
}

View file

@ -78,6 +78,7 @@ func TestRoundUp(t *testing.T) {
assert.Equal(0.5, Math.RoundUp(0.49, 0.1))
assert.Equal(1.0, Math.RoundUp(0.51, 1.0))
assert.Equal(0.4999, Math.RoundUp(0.49988, 0.0001))
assert.Equal(0.123, Math.RoundUp(0.123, 0))
}
func TestRoundDown(t *testing.T) {
@ -85,6 +86,7 @@ func TestRoundDown(t *testing.T) {
assert.Equal(0.5, Math.RoundDown(0.51, 0.1))
assert.Equal(1.0, Math.RoundDown(1.01, 1.0))
assert.Equal(0.5001, Math.RoundDown(0.50011, 0.0001))
assert.Equal(0.123, Math.RoundDown(0.123, 0))
}
func TestPercentDifference(t *testing.T) {