fixing range validation and tests.

This commit is contained in:
Will Charczuk 2017-03-02 14:39:32 -08:00
parent b2de33058f
commit 17b28beae8
2 changed files with 63 additions and 1 deletions

View file

@ -295,6 +295,9 @@ func (c Chart) checkRanges(xr, yr, yra Range) error {
if math.IsNaN(xDelta) { if math.IsNaN(xDelta) {
return errors.New("nan x-range delta") return errors.New("nan x-range delta")
} }
if xDelta == 0 {
return errors.New("zero x-range delta; there needs to be at least (2) values")
}
yDelta := yr.GetDelta() yDelta := yr.GetDelta()
if math.IsInf(yDelta, 0) { if math.IsInf(yDelta, 0) {

View file

@ -422,5 +422,64 @@ func TestChartValidatesSeries(t *testing.T) {
} }
assert.NotNil(c.validateSeries()) assert.NotNil(c.validateSeries())
}
func TestChartCheckRanges(t *testing.T) {
assert := assert.New(t)
c := Chart{
Series: []Series{
ContinuousSeries{
XValues: []float64{1.0, 2.0},
YValues: []float64{3.10, 3.14},
},
},
}
xr, yr, yra := c.getRanges()
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)
c := Chart{
XAxis: XAxis{
Range: &ContinuousRange{
Min: 0,
Max: 10,
},
},
YAxis: YAxis{
Range: &ContinuousRange{
Min: 0,
Max: 5,
},
},
Series: []Series{
ContinuousSeries{
XValues: []float64{1.0, 2.0},
YValues: []float64{3.14, 3.14},
},
},
}
xr, yr, yra := c.getRanges()
assert.Nil(c.checkRanges(xr, yr, yra))
} }