diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4680624..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 722d5e7..ab2dcb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,18 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ + +# Other .vscode +.DS_Store diff --git a/chart.go b/chart.go index 83b70ec..1354bc0 100644 --- a/chart.go +++ b/chart.go @@ -317,9 +317,6 @@ func (c Chart) checkRanges(xr, yr, yra Range) error { if math.IsNaN(yDelta) { return errors.New("nan y-range delta") } - if yDelta == 0 { - return errors.New("zero y-range delta") - } if c.hasSecondarySeries() { yraDelta := yra.GetDelta() @@ -329,9 +326,6 @@ func (c Chart) checkRanges(xr, yr, yra Range) error { if math.IsNaN(yraDelta) { return errors.New("nan secondary y-range delta") } - if yraDelta == 0 { - return errors.New("zero secondary y-range delta") - } } return nil diff --git a/chart_test.go b/chart_test.go index 6adf62d..c7d089a 100644 --- a/chart_test.go +++ b/chart_test.go @@ -443,22 +443,6 @@ func TestChartCheckRanges(t *testing.T) { assert.Nil(c.checkRanges(xr, yr, yra)) } -func TestChartCheckRangesFailure(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{1.0, 2.0}, - YValues: []float64{3.14, 3.14}, - }, - }, - } - - xr, yr, yra := c.getRanges() - assert.NotNil(c.checkRanges(xr, yr, yra)) -} - func TestChartCheckRangesWithRanges(t *testing.T) { assert := assert.New(t) diff --git a/util/math.go b/util/math.go index 73f4976..380a7f6 100644 --- a/util/math.go +++ b/util/math.go @@ -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 } diff --git a/util/math_test.go b/util/math_test.go index 8306ae2..b143948 100644 --- a/util/math_test.go +++ b/util/math_test.go @@ -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) {