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

@ -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)
}