Helper API refactor (#40)
* api cleaup * updates * wtf * updates * snapshot. * tweaks * snapshot * api tweaks. * updates * updates * updates * changes. * updates * updates * sequence => seq * dont need to use curl, just using wget * fixing examples
This commit is contained in:
parent
43212f871f
commit
03708a90ef
100 changed files with 1687 additions and 1055 deletions
|
|
@ -4,22 +4,24 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/blendlabs/go-assert"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
"github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
type mockValueProvider struct {
|
||||
type mockValuesProvider struct {
|
||||
X []float64
|
||||
Y []float64
|
||||
}
|
||||
|
||||
func (m mockValueProvider) Len() int {
|
||||
return Math.MinInt(len(m.X), len(m.Y))
|
||||
func (m mockValuesProvider) Len() int {
|
||||
return util.Math.MinInt(len(m.X), len(m.Y))
|
||||
}
|
||||
|
||||
func (m mockValueProvider) GetValue(index int) (x, y float64) {
|
||||
func (m mockValuesProvider) GetValues(index int) (x, y float64) {
|
||||
if index < 0 {
|
||||
panic("negative index at GetValue()")
|
||||
}
|
||||
if index > 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]
|
||||
|
|
@ -30,9 +32,9 @@ func (m mockValueProvider) GetValue(index int) (x, y float64) {
|
|||
func TestSMASeriesGetValue(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
mockSeries := mockValueProvider{
|
||||
Sequence.Float64(1.0, 10.0),
|
||||
Sequence.Float64(10, 1.0),
|
||||
mockSeries := mockValuesProvider{
|
||||
seq.Range(1.0, 10.0),
|
||||
seq.Range(10, 1.0),
|
||||
}
|
||||
assert.Equal(10, mockSeries.Len())
|
||||
|
||||
|
|
@ -43,7 +45,7 @@ func TestSMASeriesGetValue(t *testing.T) {
|
|||
|
||||
var yvalues []float64
|
||||
for x := 0; x < mas.Len(); x++ {
|
||||
_, y := mas.GetValue(x)
|
||||
_, y := mas.GetValues(x)
|
||||
yvalues = append(yvalues, y)
|
||||
}
|
||||
|
||||
|
|
@ -61,9 +63,9 @@ func TestSMASeriesGetValue(t *testing.T) {
|
|||
func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
mockSeries := mockValueProvider{
|
||||
Sequence.Float64(1.0, 10.0),
|
||||
Sequence.Float64(10, 1.0),
|
||||
mockSeries := mockValuesProvider{
|
||||
seq.Range(1.0, 10.0),
|
||||
seq.Range(10, 1.0),
|
||||
}
|
||||
assert.Equal(10, mockSeries.Len())
|
||||
|
||||
|
|
@ -74,11 +76,11 @@ func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
|||
|
||||
var yvalues []float64
|
||||
for x := 0; x < mas.Len(); x++ {
|
||||
_, y := mas.GetValue(x)
|
||||
_, y := mas.GetValues(x)
|
||||
yvalues = append(yvalues, y)
|
||||
}
|
||||
|
||||
lx, ly := mas.GetLastValue()
|
||||
lx, ly := mas.GetLastValues()
|
||||
assert.Equal(10.0, lx)
|
||||
assert.Equal(5.5, ly)
|
||||
assert.Equal(yvalues[len(yvalues)-1], ly)
|
||||
|
|
@ -87,9 +89,9 @@ func TestSMASeriesGetLastValueWindowOverlap(t *testing.T) {
|
|||
func TestSMASeriesGetLastValue(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
mockSeries := mockValueProvider{
|
||||
Sequence.Float64(1.0, 100.0),
|
||||
Sequence.Float64(100, 1.0),
|
||||
mockSeries := mockValuesProvider{
|
||||
seq.Range(1.0, 100.0),
|
||||
seq.Range(100, 1.0),
|
||||
}
|
||||
assert.Equal(100, mockSeries.Len())
|
||||
|
||||
|
|
@ -100,11 +102,11 @@ func TestSMASeriesGetLastValue(t *testing.T) {
|
|||
|
||||
var yvalues []float64
|
||||
for x := 0; x < mas.Len(); x++ {
|
||||
_, y := mas.GetValue(x)
|
||||
_, y := mas.GetValues(x)
|
||||
yvalues = append(yvalues, y)
|
||||
}
|
||||
|
||||
lx, ly := mas.GetLastValue()
|
||||
lx, ly := mas.GetLastValues()
|
||||
assert.Equal(100.0, lx)
|
||||
assert.Equal(6, ly)
|
||||
assert.Equal(yvalues[len(yvalues)-1], ly)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue