2016-07-16 16:10:44 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/blendlabs/go-assert"
|
|
|
|
)
|
|
|
|
|
2016-07-17 14:10:04 -04:00
|
|
|
func TestEMASeries(t *testing.T) {
|
2016-07-16 16:10:44 -04:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
mockSeries := mockValueProvider{
|
|
|
|
Seq(1.0, 10.0),
|
|
|
|
Seq(10, 1.0),
|
|
|
|
}
|
|
|
|
assert.Equal(10, mockSeries.Len())
|
|
|
|
|
2016-07-17 14:10:04 -04:00
|
|
|
mas := &EMASeries{
|
2016-07-16 16:10:44 -04:00
|
|
|
InnerSeries: mockSeries,
|
|
|
|
}
|
|
|
|
|
|
|
|
var yvalues []float64
|
|
|
|
for x := 0; x < mas.Len(); x++ {
|
|
|
|
_, y := mas.GetValue(x)
|
|
|
|
yvalues = append(yvalues, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(10.0, yvalues[0])
|
|
|
|
assert.True(math.Abs(yvalues[9]-3.77) < 0.01)
|
2016-07-16 16:25:21 -04:00
|
|
|
|
|
|
|
lvx, lvy := mas.GetLastValue()
|
|
|
|
assert.Equal(10.0, lvx)
|
|
|
|
assert.True(math.Abs(lvy-3.77) < 0.01)
|
2016-07-16 16:10:44 -04:00
|
|
|
}
|