This commit is contained in:
Will Charczuk 2017-04-30 01:12:15 -07:00
parent c47025edf6
commit 41d81c82db
4 changed files with 30 additions and 6 deletions

View File

@ -505,8 +505,8 @@ func TestChartE2ELine(t *testing.T) {
},
Series: []Series{
ContinuousSeries{
XValues: sequence.Values(0, 4, 1),
YValues: sequence.Values(0, 4, 1),
XValues: sequence.ValuesWithStep(0, 4, 1),
YValues: sequence.ValuesWithStep(0, 4, 1),
},
},
}
@ -550,8 +550,8 @@ func TestChartE2ELineWithFill(t *testing.T) {
StrokeColor: drawing.ColorBlue,
FillColor: drawing.ColorRed,
},
XValues: sequence.Values(0, 4, 1),
YValues: sequence.Values(0, 4, 1),
XValues: sequence.ValuesWithStep(0, 4, 1),
YValues: sequence.ValuesWithStep(0, 4, 1),
},
},
}

View File

@ -24,7 +24,7 @@ type Linear struct {
// Len returns the number of elements in the sequence.
func (lg Linear) Len() int {
return int((lg.limit - lg.offset) / lg.step)
return (int((lg.limit - lg.offset) / lg.step)) + 1
}
// GetValue returns the value at a given index.

24
sequence/linear_test.go Normal file
View File

@ -0,0 +1,24 @@
package sequence
import (
"testing"
assert "github.com/blendlabs/go-assert"
)
func TestValues(t *testing.T) {
assert := assert.New(t)
values := Values(1, 100)
assert.Len(values, 100)
assert.Equal(1, values[0])
assert.Equal(100, values[99])
}
func TestValueWithStep(t *testing.T) {
assert := assert.New(t)
values := ValuesWithStep(0, 100, 5)
assert.Equal(100, values[20])
assert.Len(values, 21)
}

View File

@ -21,7 +21,7 @@ func (m mockValuesProvider) GetValues(index int) (x, y float64) {
if index < 0 {
panic("negative index at GetValue()")
}
if index > util.Math.MinInt(len(m.X), len(m.Y)) {
if index >= util.Math.MinInt(len(m.X), len(m.Y)) {
panic("index is outside the length of m.X or m.Y")
}
x = m.X[index]