This repository was archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgocurrency_test.go
More file actions
68 lines (64 loc) · 1.45 KB
/
Copy pathgocurrency_test.go
File metadata and controls
68 lines (64 loc) · 1.45 KB
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
package gocurrency
import (
"testing"
)
func TestAvailableCurrenciesBases(t *testing.T) {
cases := []struct {
in, want string
}{
{"EUR", "EUR"},
{"HKD", "HKD"},
{"", "EUR"},
}
for _, c := range cases {
goCurrency, _ := GetCurrencies(&Parameters{
base: c.in,
})
if goCurrency.base != c.want {
t.Errorf("GetCurrencies(%q) == %q, want %q", c.in, goCurrency.base, c.want)
}
}
}
func TestAvailableCurrenciesDates(t *testing.T) {
cases := []struct {
in, want string
}{
{"2013-02-04", "2013-02-04"},
{"2012-01-02", "2012-01-02"},
{"", "latest"},
}
for _, c := range cases {
goCurrency, _ := GetCurrencies(&Parameters{
date: c.in,
})
if goCurrency.date != c.want && c.in != "" {
t.Errorf("GetCurrencies(%q) == %q, want %q", c.in, goCurrency.date, c.want)
}
}
}
func TestAvailableCurrenciesSymbols(t *testing.T) {
cases := []struct{
base string
symbols []string
numRates int
}{
{"", []string{"CAD", "ZAR", "RUB"}, 3},
{"EUR", []string{"SEK"}, 1},
{"DKK", []string{"EUR"}, 1},
{"USD", []string{}, 31},
}
for _, c := range cases {
goCurrency, _ := GetCurrencies(&Parameters{
base: c.base,
symbols: c.symbols,
})
if c.numRates != len(goCurrency.rates) {
t.Errorf("numRates == %q, want %q", len(goCurrency.rates), c.numRates)
}
for _, symbol := range c.symbols {
if _, ok := goCurrency.rates[symbol]; ok != true {
t.Errorf("Symbol %q not found in map", symbol, goCurrency.rates)
}
}
}
}