-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv8_test.go
139 lines (122 loc) · 2.86 KB
/
v8_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package goyfinance
import (
"fmt"
"testing"
)
func aaplList(n int) []string {
var aaplList []string
for i := 0; i < n; i++ {
aaplList = append(aaplList, "AAPL")
}
return aaplList
}
func testAAPLQuote(quote Quote) {
if quote.Ticker != "AAPL" {
panic("Ticker is not AAPL")
}
var fields []struct {
name string
val interface{}
}
for _, field := range fields {
if field.val == 0 {
panic(field.name + " is 0")
}
}
}
func TestGetQuote(t *testing.T) {
quote, err := GetQuote("AAPL", IntervalOneDay, PeriodOneMonth)
if err != nil {
t.Error(err)
}
testAAPLQuote(quote)
}
func TestGetQuoteBatch(t *testing.T) {
quotes, err := GetQuoteBatch(aaplList(10), IntervalOneDay, PeriodOneMonth)
if err != nil {
t.Error(err)
}
for _, quote := range quotes {
testAAPLQuote(quote)
}
}
func TestExampleUsage(t *testing.T) {
// Define a bunch of tickers
tickerList := []string{"AAPL", "MSFT", "GOOG", "TSLA", "AMZN"}
// Get quote data for all the tickers
quotes, err := GetQuoteBatch(tickerList, IntervalOneDay, PeriodFiveDays)
// Check for errors
if err != nil {
t.Error(err)
}
// Use the quotes
fmt.Printf("Three days ago, %s closed at $%.2f\n", quotes[0].Ticker, quotes[0].PriceHistoric[2].ClosePrice)
fmt.Printf("Now, the volume of %s is %d\n", quotes[1].Ticker, quotes[1].PriceHistoric[0].Volume)
}
func BenchmarkGetQuoteJSON(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteJSON("AAPL", IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteJSONBatch(b *testing.B) {
b.StopTimer()
aaplist := aaplList(10)
b.StartTimer()
for n := 0; n < b.N; n++ {
_, err := GetQuoteJSONBatch(aaplist, IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteJSONString(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteJSONString("AAPL", IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteJSONStringBatch(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteJSONStringBatch(aaplList(10), IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuote(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuote("AAPL", IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteBatch(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteBatch(aaplList(10), IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteCSVString(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteCSVString("AAPL", IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkGetQuoteCSVStringBatch(b *testing.B) {
for n := 0; n < b.N; n++ {
_, err := GetQuoteCSVStringBatch(aaplList(10), IntervalOneDay, PeriodOneMonth)
if err != nil {
b.Error(err)
}
}
}