-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv2_test.go
72 lines (61 loc) · 1.42 KB
/
csv2_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
package csv2
import (
"testing"
"time"
)
const (
testFile = "test.csv"
)
// date,close,high,low,open,volume,adjClose,adjHigh,adjLow,adjOpen,adjVolume,divCash,splitFactor
// Daily price structure for each row.
type dailyPrice struct {
Date time.Time `format:"2006-01-02 15:04:05-07:00"`
Close float64
High float64
Low float64
Open float64
Volume int64
AdjClose float64
AdjHigh float64
AdjLow float64
AdjOpen float64
AdjVolume int64
DivCash float64
SplitFactor float64
}
// Stock prices structure for all columns.
type stockPrices struct {
Date []time.Time `format:"2006-01-02 15:04:05-07:00"`
Close []float64
High []float64
Low []float64
Open []float64
Volume []int64
AdjClose []float64
AdjHigh []float64
AdjLow []float64
AdjOpen []float64
AdjVolume []int64
DivCash []float64
SplitFactor []float64
}
func TestReadRowsFromFile(t *testing.T) {
var prices []dailyPrice
err := ReadRowsFromFile(testFile, true, &prices)
if err != nil {
t.Fatal(err)
}
if n := len(prices); n != 10 {
t.Fatalf("prices must have 10 element but has %d", n)
}
}
func TestReadTableFromFile(t *testing.T) {
prices := stockPrices{}
err := ReadTableFromFile(testFile, true, &prices)
if err != nil {
t.Fatal(err)
}
if n := len(prices.Date); n != 10 {
t.Fatalf("date must have 10 elements but has %d", n)
}
}