This repository was archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathpendulumLevelProvider_test.go
More file actions
74 lines (68 loc) · 1.79 KB
/
pendulumLevelProvider_test.go
File metadata and controls
74 lines (68 loc) · 1.79 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
69
70
71
72
73
74
package plugins
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetLastPriceFromMap(t *testing.T) {
price2LastPriceMap := map[float64]float64{
0.075: 0.070, // sell side because offer price (key) is greater than last price (value)
0.074: 0.080, // buy side because offer price (key) is less than last price (value)
}
testCases := []struct {
price2LastPrice map[float64]float64
tradePrice float64
isBuy bool
wantTradePrice float64
wantLastPrice float64
}{
{
price2LastPrice: price2LastPriceMap,
tradePrice: 0.075,
isBuy: false,
wantTradePrice: 0.075,
wantLastPrice: 0.070,
}, {
price2LastPrice: price2LastPriceMap,
tradePrice: 0.074,
isBuy: false,
wantTradePrice: 0.075,
wantLastPrice: 0.070,
}, {
price2LastPrice: price2LastPriceMap,
tradePrice: 0.0745,
isBuy: false,
wantTradePrice: 0.075,
wantLastPrice: 0.070,
}, {
price2LastPrice: price2LastPriceMap,
tradePrice: 0.074,
isBuy: true,
wantTradePrice: 0.074,
wantLastPrice: 0.080,
}, {
price2LastPrice: price2LastPriceMap,
tradePrice: 0.075,
isBuy: true,
wantTradePrice: 0.074,
wantLastPrice: 0.080,
}, {
price2LastPrice: price2LastPriceMap,
tradePrice: 0.0745,
isBuy: true,
wantTradePrice: 0.074,
wantLastPrice: 0.080,
},
}
for _, kase := range testCases {
t.Run(fmt.Sprintf("%.4f/%v", kase.tradePrice, kase.isBuy), func(t *testing.T) {
lastTradePrice, lastPrice := getLastPriceFromMap(kase.price2LastPrice, kase.tradePrice, kase.isBuy)
if !assert.Equal(t, kase.wantTradePrice, lastTradePrice) {
return
}
if !assert.Equal(t, kase.wantLastPrice, lastPrice) {
return
}
})
}
}