@@ -9,55 +9,101 @@ import (
9
9
func TestAmountToLotSize (t * testing.T ) {
10
10
assert := assert .New (t )
11
11
type args struct {
12
- lot float64
12
+ minQty string
13
+ stepSize string
14
+ amount string
13
15
precision int
14
- amount float64
15
16
}
16
17
tests := []struct {
17
- name string
18
- args args
19
- want float64
18
+ name string
19
+ args args
20
+ expect string
20
21
}{
21
22
{
22
23
name : "test with lot of zero and invalid amount" ,
23
24
args : args {
24
- lot : 0.00100000 ,
25
+ minQty : "0.01" ,
26
+ stepSize : "0.01" ,
27
+ amount : "0.001" ,
25
28
precision : 8 ,
26
- amount : 0.00010000 ,
27
29
},
28
- want : 0 ,
30
+ expect : "0" ,
29
31
},
30
32
{
31
33
name : "test with lot" ,
32
34
args : args {
33
- lot : 0.00100000 ,
34
- precision : 3 ,
35
- amount : 1.39 ,
35
+ minQty : "0.01" ,
36
+ stepSize : "0.01" ,
37
+ amount : "1.39" ,
38
+ precision : 8 ,
39
+ },
40
+ expect : "1.39" ,
41
+ },
42
+ {
43
+ name : "test with exact precision" ,
44
+ args : args {
45
+ minQty : "0.01" ,
46
+ stepSize : "0.01" ,
47
+ amount : "1.39" ,
48
+ precision : 2 ,
49
+ },
50
+ expect : "1.39" ,
51
+ },
52
+ {
53
+ name : "test with small precision" ,
54
+ args : args {
55
+ minQty : "0.01" ,
56
+ stepSize : "0.01" ,
57
+ amount : "1.39" ,
58
+ precision : 1 ,
36
59
},
37
- want : 1.389 ,
60
+ expect : "1.3" ,
61
+ },
62
+ {
63
+ name : "test with zero precision" ,
64
+ args : args {
65
+ minQty : "0.01" ,
66
+ stepSize : "0.01" ,
67
+ amount : "1.39" ,
68
+ precision : 0 ,
69
+ },
70
+ expect : "1" ,
38
71
},
39
72
{
40
73
name : "test with big decimal" ,
41
74
args : args {
42
- lot : 0.00100000 ,
75
+ minQty : "0.01" ,
76
+ stepSize : "0.02" ,
77
+ amount : "11.31232419283240912834434" ,
43
78
precision : 8 ,
44
- amount : 11.31232419283240912834434 ,
45
79
},
46
- want : 11.312 ,
80
+ expect : " 11.31" ,
47
81
},
48
82
{
49
83
name : "test with big number" ,
50
84
args : args {
51
- lot : 0.0010000 ,
85
+ minQty : "0.0001" ,
86
+ stepSize : "0.02" ,
87
+ amount : "11232821093480213.31232419283240912834434" ,
52
88
precision : 8 ,
53
- amount : 11232821093480213.31232419283240912834434 ,
54
89
},
55
- want : 11232821093480213.3123 ,
90
+ expect : "11232821093480213.3001" ,
91
+ },
92
+ {
93
+ name : "test with small decimal" ,
94
+ args : args {
95
+ minQty : "0.0000010" ,
96
+ stepSize : "0.0000010" ,
97
+ amount : "0.003923153000000002" ,
98
+ precision : 7 ,
99
+ },
100
+ expect : "0.003923" ,
56
101
},
57
102
}
103
+
58
104
for _ , tt := range tests {
59
105
t .Run (tt .name , func (t * testing.T ) {
60
- assert .Equal (tt .want , AmountToLotSize (tt .args .lot , tt .args .precision , tt .args .amount ))
106
+ assert .Equal (tt .expect , AmountToLotSize (tt .args .amount , tt .args .minQty , tt .args .stepSize , tt . args . precision ))
61
107
})
62
108
}
63
109
}
0 commit comments