-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarket_test.go
213 lines (186 loc) · 6.36 KB
/
market_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package coinmarket
import (
"github.com/smartystreets/goconvey/convey"
"testing"
)
func TestCheckFirstMethod(t *testing.T) {
convey.Convey("When first method of tickerResponse called empty", t, func() {
convey.Convey("Response must be error", func() {
response := TickerResponse{}
item, err := response.First()
convey.So(item, convey.ShouldBeNil)
convey.So(err, convey.ShouldBeError)
})
convey.Convey("Response.name must be Siacoin", func() {
response := getFakeResponse()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Siacoin")
})
})
}
func TestCheckLastMethod(t *testing.T) {
convey.Convey("When first method of tickerResponse called empty, the response must be error", t, func() {
convey.Convey("Response must be error", func() {
response := TickerResponse{}
item, err := response.Last()
convey.So(item, convey.ShouldBeNil)
convey.So(err, convey.ShouldBeError)
})
convey.Convey("Response.name must be NXT", func() {
response := getFakeResponse()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByPriceBtc(t *testing.T) {
convey.Convey("SortByPriceBtc must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByPriceBtc()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByPriceBtc()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByPercentChange1H(t *testing.T) {
convey.Convey("PercentChange1H must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByPercentChange1H()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByPercentChange1H()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByPercentChange7D(t *testing.T) {
convey.Convey("SortByPercentChange7D must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByPercentChange7D()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByPercentChange7D()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByPercentChange24H(t *testing.T) {
convey.Convey("SortByPercentChange24H must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByPercentChange24H()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByPercentChange24H()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByAvailableSupply(t *testing.T) {
convey.Convey("SortByAvailableSupply must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByAvailableSupply()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByAvailableSupply()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestSortByMarketCapUsd(t *testing.T) {
convey.Convey("SortByMarketCapUsd must be return list in order", t, func() {
response := getFakeResponse()
convey.Convey("First item must be bitcoin", func() {
response.SortByMarketCapUsd()
item, err := response.First()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Last item must be NXT", func() {
response.SortByMarketCapUsd()
item, err := response.Last()
convey.So(err, convey.ShouldBeNil)
convey.So(item.Name, convey.ShouldEqual, "NXT")
})
})
}
func TestGetCoinNameStartWith(t *testing.T) {
convey.Convey("Search by name prefix", t, func() {
response := getFakeResponse()
convey.Convey("Must be return Bitcoin", func() {
Itens := response.GetCoinNameStartsWith("bit")
convey.So(Itens[0].Name, convey.ShouldEqual, "Bitcoin")
})
convey.Convey("Must be return one item", func() {
Itens := response.GetCoinNameStartsWith("bit")
convey.So(len(Itens), convey.ShouldEqual, 1)
})
})
}
func TestGetCoinSymbolStartsWith(t *testing.T) {
convey.Convey("Search by Symbol prefix", t, func() {
response := getFakeResponse()
convey.Convey("Must be return Bitcoin", func() {
Itens := response.GetCoinSymbolStartsWith("btc")
convey.So(Itens[0].Symbol, convey.ShouldEqual, "BTC")
})
convey.Convey("Must be return one item", func() {
Itens := response.GetCoinSymbolStartsWith("btc")
convey.So(len(Itens), convey.ShouldEqual, 1)
})
})
}
func getFakeResponse() *TickerResponse {
response := TickerResponse{
TickerList: []TickerItem{},
}
response.TickerList = append(response.TickerList, TickerItem{
Symbol: "SC", Name: "Siacoin", MarketCapUsd: "5",
PriceBtc: "5", AvailableSupply: "5", PercentChange24H: "5",
PercentChange7D: "5", PercentChange1H: "5",
})
response.TickerList = append(response.TickerList, TickerItem{
Symbol: "BTC", Name: "Bitcoin", MarketCapUsd: "10",
PriceBtc: "10", AvailableSupply: "10", PercentChange24H: "10",
PercentChange7D: "10", PercentChange1H: "10",
})
response.TickerList = append(response.TickerList, TickerItem{
Symbol: "NXT", Name: "NXT", MarketCapUsd: "2",
PriceBtc: "2", AvailableSupply: "2", PercentChange24H: "2",
PercentChange7D: "2", PercentChange1H: "2",
})
return &response
}