2017-05-13 02:12:23 +02:00
|
|
|
package seq
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-05 09:42:38 +02:00
|
|
|
assert "github.com/blend/go-sdk/assert"
|
2017-05-13 02:12:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRange(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
values := Range(1, 100)
|
2018-04-05 09:47:39 +02:00
|
|
|
assert.Len(100, values)
|
2017-05-13 02:12:23 +02: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-04-05 09:47:39 +02:00
|
|
|
assert.Len(21, values)
|
2017-05-13 02:12:23 +02: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-04-05 09:47:39 +02:00
|
|
|
assert.Len(100, values)
|
2017-05-13 02:12:23 +02:00
|
|
|
assert.Equal(1.0, values[0])
|
|
|
|
assert.Equal(100, values[99])
|
|
|
|
}
|