2017-05-12 20:12:23 -04:00
|
|
|
package seq
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-05 03:42:38 -04:00
|
|
|
assert "github.com/blend/go-sdk/assert"
|
2017-05-12 20:12:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRange(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
values := Range(1, 100)
|
2018-09-05 11:45:19 -04:00
|
|
|
assert.Len(values, 100)
|
2017-05-12 20:12:23 -04:00
|
|
|
assert.Equal(1, values[0])
|
|
|
|
assert.Equal(100, values[99])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRangeWithStep(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
values := RangeWithStep(0, 100, 5)
|
|
|
|
assert.Equal(100, values[20])
|
2018-09-05 11:45:19 -04:00
|
|
|
assert.Len(values, 21)
|
2017-05-12 20:12:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRangeReversed(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
values := Range(10.0, 1.0)
|
|
|
|
assert.Equal(10, len(values))
|
|
|
|
assert.Equal(10.0, values[0])
|
|
|
|
assert.Equal(1.0, values[9])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValuesRegression(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
// note; this assumes a 1.0 step is implicitly set in the constructor.
|
|
|
|
linearProvider := NewLinear().WithStart(1.0).WithEnd(100.0)
|
|
|
|
assert.Equal(1, linearProvider.Start())
|
|
|
|
assert.Equal(100, linearProvider.End())
|
|
|
|
assert.Equal(100, linearProvider.Len())
|
|
|
|
|
|
|
|
values := Seq{Provider: linearProvider}.Array()
|
2018-09-05 11:45:19 -04:00
|
|
|
assert.Len(values, 100)
|
2017-05-12 20:12:23 -04:00
|
|
|
assert.Equal(1.0, values[0])
|
|
|
|
assert.Equal(100, values[99])
|
|
|
|
}
|