forked from edgmic/yquotes
/
yquotes_test.go
48 lines (40 loc) · 1.17 KB
/
yquotes_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
package yquotes
import (
"github.com/doneland/test"
"testing"
"time"
)
// Create new stock object with recent price information and historical
// prices.
func TestCreateStock(t *testing.T) {
symbol := "AAPL"
stock, err := NewStock(symbol, true)
test.Ok(t, err)
test.Equals(t, symbol, stock.Symbol)
}
// Get stock price data.
func TestGetStockPrice(t *testing.T) {
symbol := "AAPL"
price, err := GetPrice(symbol)
test.Ok(t, err)
test.Assert(t, price.Bid != 0, "Bid price should not be equal to zero.")
}
// Get stock price history.
func TestStockPriceHistory(t *testing.T) {
symbol := "AAPL"
from, _ := time.Parse("2006-01-02", "2015-01-01")
to, _ := time.Parse("2006-01-02", "2015-04-10")
prices, err := GetDailyHistory(symbol, from, to)
test.Ok(t, err)
test.Equals(t, int(4), int(prices[0].Date.Month()))
test.Equals(t, int(10), int(prices[0].Date.Day()))
test.Equals(t, int(2015), int(prices[0].Date.Year()))
}
// Get stock price for one day.
func TestGetStockPriceForDay(t *testing.T) {
symbol := "AAPL"
date, _ := time.Parse("2006-01-02", "2015-04-09")
price, err := GetPriceForDate(symbol, date)
test.Ok(t, err)
test.Equals(t, int(4), int(price.Date.Month()))
}