-
Notifications
You must be signed in to change notification settings - Fork 1
/
candle_test.go
66 lines (55 loc) · 1.29 KB
/
candle_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
package stockutil
import (
"testing"
"time"
)
func TestFlatCandleAppend(t *testing.T) {
// TODO: Implement
t.Skip()
}
func loadFlatCandle() *FlatCandle {
var ticks []Tick
for _, v := range testseries {
t := Tick{
Time: time.Unix(int64(v[0]), 0),
Value: v[1],
}
ticks = append(ticks, t)
}
dur, _ := time.ParseDuration("15m")
return TicksToFlatCandle(ticks, dur)
}
func TestFlatCandleGet(t *testing.T) {
fcandle := loadFlatCandle()
c, _ := fcandle.Get(1)
if c.Open != 439.47 || c.High != 439.49 || c.Low != 437.55 || c.Close != 438.93 ||
c.Time != fcandle.Time[1] || c.Duration != fcandle.Duration {
t.Errorf("%v\n", c)
}
}
func TestTicksToFlatCandle(t *testing.T) {
fcandle := loadFlatCandle()
if x := len(fcandle.Open); x != 75 {
t.Errorf("%v\n", x)
}
if x := fcandle.Open[1]; x != 439.47 {
t.Errorf("%v\n", x)
}
if x := fcandle.High[1]; x != 439.49 {
t.Errorf("%v\n", x)
}
if x := fcandle.Low[1]; x != 437.55 {
t.Errorf("%v\n", x)
}
if x := fcandle.Close[1]; x != 438.93 {
t.Errorf("%v\n", x)
}
tt, _ := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", "2015-12-22 01:40:00 +0100 CET")
if x := fcandle.Time[1]; x != tt {
t.Errorf("%v\n", x)
}
dur, _ := time.ParseDuration("15m")
if x := fcandle.Duration; x != dur {
t.Errorf("%v\n", x)
}
}