-
Notifications
You must be signed in to change notification settings - Fork 1
/
price_test.go
48 lines (42 loc) · 1.18 KB
/
price_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 coin
import (
"fmt"
"strings"
"testing"
"github.com/mkobetic/coin/assert"
)
func init() {
Commodities["TDB162"] = &Commodity{Id: "TDB162", Decimals: 4}
}
func Test_ParsePrice(t *testing.T) {
r := strings.NewReader(`
P 1988/06/29 TDB162 9.69 CAD
P 1988/07/28 TDB162 9.58 CAD
P 1988/08/30 TDB162 9.45 CAD
`)
p := NewParser(r)
i, err := p.Next("")
assert.NoError(t, err)
pr, ok := i.(*Price)
assert.Equal(t, ok, true)
assert.Equal(t, pr.CommodityId, "TDB162")
assert.Equal(t, pr.currencyId, "CAD")
assert.Equal(t, pr.Time.Format(DateFormat), "1988/06/29")
assert.Equal(t, fmt.Sprintf("%a", pr.Value), "9.69")
i, err = p.Next("")
assert.NoError(t, err)
pr, ok = i.(*Price)
assert.Equal(t, ok, true)
assert.Equal(t, pr.CommodityId, "TDB162")
assert.Equal(t, pr.currencyId, "CAD")
assert.Equal(t, pr.Time.Format(DateFormat), "1988/07/28")
assert.Equal(t, fmt.Sprintf("%a", pr.Value), "9.58")
i, err = p.Next("")
assert.NoError(t, err)
pr, ok = i.(*Price)
assert.Equal(t, ok, true)
assert.Equal(t, pr.CommodityId, "TDB162")
assert.Equal(t, pr.currencyId, "CAD")
assert.Equal(t, pr.Time.Format(DateFormat), "1988/08/30")
assert.Equal(t, fmt.Sprintf("%a", pr.Value), "9.45")
}