-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpriceTable_test.go
48 lines (39 loc) · 919 Bytes
/
priceTable_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 coinmarketcap
import (
"testing"
)
func TestPriceTableAdd(t *testing.T) {
table := make(priceTable)
err := table.add("price_usd", "12.2", "price_")
if err != nil {
t.Fatalf("add() failed on good input: %s", err.Error())
}
if table["USD"] != 12.2 {
t.Errorf("USD is not 12.2, got %f", table["USD"])
}
}
func TestPriceTableAddError(t *testing.T) {
table := make(priceTable)
err := table.add("price_usd", "not-float", "price_")
if err == nil {
t.Fatalf("add() failed to err")
}
}
func TestPriceTableGet(t *testing.T) {
table := make(priceTable)
table["USD"] = 12.3
value, err := table.get("USD")
if err != nil {
t.Fatalf("get() errored: %s", err.Error())
}
if value != 12.3 {
t.Errorf("got %f, expected 12.3", value)
}
}
func TestPriceTableGetError(t *testing.T) {
table := make(priceTable)
_, err := table.get("BOOM")
if err == nil {
t.Fatalf("get() failed to err")
}
}