Debian Codegraph @

bollinger_band_series_test.go

raw symbols SCIP
1 package chart
2
3 import (
4 "fmt"
5 "math"
6 "testing"
7
8 "github.com/wcharczuk/go-chart/v2/testutil"
9 )
10
11 func TestBollingerBandSeries(t *testing.T) {
12 // replaced new assertions helper
13
14 s1 := mockValuesProvider{
15 X: LinearRange(1.0, 100.0),
16 Y: RandomValuesWithMax(100, 1024),
17 }
18
19 bbs := &BollingerBandsSeries{
20 InnerSeries: s1,
21 }
22
23 xvalues := make([]float64, 100)
24 y1values := make([]float64, 100)
25 y2values := make([]float64, 100)
26
27 for x := 0; x < 100; x++ {
28 xvalues[x], y1values[x], y2values[x] = bbs.GetBoundedValues(x)
29 }
30
31 for x := bbs.GetPeriod(); x < 100; x++ {
32 testutil.AssertTrue(t, y1values[x] > y2values[x], fmt.Sprintf("%v vs. %v", y1values[x], y2values[x]))
33 }
34 }
35
36 func TestBollingerBandLastValue(t *testing.T) {
37 // replaced new assertions helper
38
39 s1 := mockValuesProvider{
40 X: LinearRange(1.0, 100.0),
41 Y: LinearRange(1.0, 100.0),
42 }
43
44 bbs := &BollingerBandsSeries{
45 InnerSeries: s1,
46 }
47
48 x, y1, y2 := bbs.GetBoundedLastValues()
49 testutil.AssertEqual(t, 100.0, x)
50 testutil.AssertEqual(t, 101, math.Floor(y1))
51 testutil.AssertEqual(t, 83, math.Floor(y2))
52 }