-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils_test.go
125 lines (119 loc) · 2.17 KB
/
utils_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAmountToLotSize(t *testing.T) {
assert := assert.New(t)
type args struct {
minQty string
stepSize string
amount string
precision int
}
tests := []struct {
name string
args args
expect string
}{
{
name: "test with lot of zero and invalid amount",
args: args{
minQty: "0.01",
stepSize: "0.01",
amount: "0.001",
precision: 8,
},
expect: "0",
},
{
name: "test with lot",
args: args{
minQty: "0.01",
stepSize: "0.01",
amount: "1.39",
precision: 8,
},
expect: "1.39",
},
{
name: "test with exact precision",
args: args{
minQty: "0.01",
stepSize: "0.01",
amount: "1.39",
precision: 2,
},
expect: "1.39",
},
{
name: "test with small precision",
args: args{
minQty: "0.01",
stepSize: "0.01",
amount: "1.39",
precision: 1,
},
expect: "1.3",
},
{
name: "test with zero precision",
args: args{
minQty: "0.01",
stepSize: "0.01",
amount: "1.39",
precision: 0,
},
expect: "1",
},
{
name: "test with big decimal",
args: args{
minQty: "0.01",
stepSize: "0.02",
amount: "11.31232419283240912834434",
precision: 8,
},
expect: "11.31",
},
{
name: "test with big number",
args: args{
minQty: "0.0001",
stepSize: "0.02",
amount: "11232821093480213.31232419283240912834434",
precision: 8,
},
expect: "11232821093480213.3001",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(tt.expect, AmountToLotSize(tt.args.amount, tt.args.minQty, tt.args.stepSize, tt.args.precision))
})
}
}
func TestStrToPct(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
s string
expect float64
}{
{
name: "test with percentage sign",
s: "81%",
expect: 0.81,
},
{
name: "test with float",
s: "0.12",
expect: 0.12,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.InDelta(tt.expect, StrToPct(tt.s), 0.00000000000001)
})
}
}