-
Notifications
You must be signed in to change notification settings - Fork 0
/
highest_test.go
111 lines (107 loc) · 2.27 KB
/
highest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package shingo
import (
"testing"
)
func TestHighest(t *testing.T) {
hTests := []struct {
title string
arg IndicatorInputArg
candles []*Candlestick
expected []float64
}{
{
title: "Should get highest value for period up to that candlestick",
arg: IndicatorInputArg{
Type: IndicatorTypeHighest,
Period: 10,
},
candles: []*Candlestick{
&Candlestick{Close: 52.22},
&Candlestick{Close: 52.78},
&Candlestick{Close: 53.02},
&Candlestick{Close: 53.67},
&Candlestick{Close: 53.67},
&Candlestick{Close: 53.74},
&Candlestick{Close: 53.45},
&Candlestick{Close: 53.72},
&Candlestick{Close: 53.39},
&Candlestick{Close: 52.51},
&Candlestick{Close: 52.32},
&Candlestick{Close: 51.45},
&Candlestick{Close: 51.60},
&Candlestick{Close: 52.43},
&Candlestick{Close: 52.47},
&Candlestick{Close: 52.91},
&Candlestick{Close: 52.07},
&Candlestick{Close: 53.12},
&Candlestick{Close: 52.77},
&Candlestick{Close: 52.73},
&Candlestick{Close: 52.09},
&Candlestick{Close: 53.19},
&Candlestick{Close: 53.73},
&Candlestick{Close: 53.87},
&Candlestick{Close: 53.85},
&Candlestick{Close: 53.88},
&Candlestick{Close: 54.08},
&Candlestick{Close: 54.14},
&Candlestick{Close: 54.50},
&Candlestick{Close: 54.30},
&Candlestick{Close: 54.40},
&Candlestick{Close: 54.16},
},
expected: []float64{
52.22,
52.78,
53.02,
53.67,
53.67,
53.74,
53.74,
53.74,
53.74,
53.74,
53.74,
53.74,
53.74,
53.74,
53.74,
53.72,
53.72,
53.39,
53.12,
53.12,
53.12,
53.19,
53.73,
53.87,
53.87,
53.88,
54.08,
54.14,
54.50,
54.50,
54.50,
54.50,
},
},
}
for _, st := range hTests {
cs, _ := NewCandlesticks(IntervalOneDay, 100)
for _, c := range st.candles {
cs.AppendCandlestick(c)
}
if err := cs.GenerateIndicator(IndicatorTypeHighest, st.arg); err != nil {
t.Fatalf("Error appending stddev: %+v", err)
}
for i, e := range st.expected {
v := cs.ItemAtIndex(i)
high := v.GetHighest(st.arg.Period)
if high == nil {
continue
}
if !equalWithinPct(e, *high, 0.005) {
t.Errorf("Expected value to be: %+v but got %+v", e, high)
}
}
}
}