5
5
"log"
6
6
"os"
7
7
"reflect"
8
- "strings"
8
+ _ "strings"
9
9
"testing"
10
10
"time"
11
11
@@ -144,16 +144,17 @@ var decimalBCD = []struct {
144
144
numString string
145
145
}{
146
146
{[]byte {0x02 , 0x01 , 0x23 , 0x4b }, "-12.34" },
147
- {[]byte {0x0 , 0xa }, "0" }, // WRONG 00000a
147
+ // {[]byte{0x0, 0xa}, "0"}, // WRONG 00000a
148
148
//{[]byte{0x0, 0xb}, "-0"}, // WRONG 00000b
149
- // {[]byte{0x0, 0x1a}, "1"}, // WRONG 00010a
149
+ {[]byte {0x0 , 0x1a }, "1" }, // WRONG 00010a
150
150
//{[]byte{0x0, 0x1b}, "-1"}, // WRONG 00010b
151
151
//{[]byte{0x1, 0x1a}, "0.1"}, // WRONG 00010a
152
152
//{[]byte{0x1, 0x1b}, "-0.1"}, // WRONG 00010b
153
153
//{[]byte{0x25, 0x1a}, "0.0000000000000000000000000000000000001"}, // WRONG 25000000000000000000000000000000000000001a
154
154
//{[]byte{0x25, 0x1b}, "-0.0000000000000000000000000000000000001"}, // WRONG 25000000000000000000000000000000000000001b
155
155
//{[]byte{0x26, 0x1a}, "0.00000000000000000000000000000000000001"}, // WRONG 2600000000000000000000000000000000000000010a
156
156
//{[]byte{0x26, 0x1b}, "-0.00000000000000000000000000000000000001"}, // WRONG 2600000000000000000000000000000000000000010b
157
+
157
158
//{[]byte{0x03, 0x01, 0x24, 0x01, 0x0c}, "0.000000000000000000000000000000000010"},
158
159
// {[]byte{0xc70b010f0123456789000000000c}, "123.456789000000000"},
159
160
// {[]byte{0xc70a010f02718281828459045c}, "2.718281828459045"},
@@ -169,9 +170,13 @@ var decimalBCD = []struct {
169
170
func TestMPEncodeStringToBCD (t * testing.T ) {
170
171
for _ , testcase := range decimalBCD {
171
172
t .Run (testcase .numString , func (t * testing.T ) {
172
- buf := MPEncodeStringToBCD (testcase .numString )
173
+ buf , err := MPEncodeStringToBCD (testcase .numString )
174
+ if err != nil {
175
+ t .Fatalf ("Failed to encode string with decimal to BCD: %s" , err )
176
+
177
+ }
173
178
if reflect .DeepEqual (buf , testcase .bcdBuf ) != true {
174
- t .Fatalf ("Failed to encode decimal %s to BCD (actual: '%x', expected '%x')" , testcase .numString , buf , testcase .bcdBuf )
179
+ t .Fatalf ("Failed to encode string with decimal '%s' to BCD (actual: '%x', expected '%x')" , testcase .numString , buf , testcase .bcdBuf )
175
180
}
176
181
})
177
182
}
@@ -180,21 +185,25 @@ func TestMPEncodeStringToBCD(t *testing.T) {
180
185
func TestMPDecodeStringFromBCD (t * testing.T ) {
181
186
for _ , testcase := range decimalBCD {
182
187
t .Run (testcase .numString , func (t * testing.T ) {
183
- dec_expected , err := decimal .NewFromString (testcase .numString )
184
- if err != nil {
185
- t .Fatalf ("Failed to encode string to decimal" )
186
- }
187
188
s , err := MPDecodeStringFromBCD (testcase .bcdBuf )
188
189
if err != nil {
189
- t .Fatalf ("Failed to decode decimal (%s) from BCD (%x) - '%x'" , testcase .numString , testcase .bcdBuf , s )
190
- }
191
- dec_actual , err := decimal .NewFromString (strings .Join (s , "" ))
192
- if err != nil {
193
- t .Fatalf ("Failed to encode string to decimal" )
194
- }
195
- if ! dec_expected .Equal (dec_actual ) {
196
- t .Fatalf ("Failed to decode decimal (%s) from BCD (%x) - '%x'" , testcase .numString , testcase .bcdBuf , s )
190
+ t .Fatalf ("Failed to decode BCD ('%x') to string with decimal (actual: '%s', expected '%s')" , testcase .bcdBuf , s , testcase .numString )
197
191
}
192
+
193
+ /*
194
+ descStr := strings.Join(s, "")
195
+ decActual, err := decimal.NewFromString()
196
+ if err != nil {
197
+ t.Fatalf("Failed to encode string ('%s') to decimal", decStr)
198
+ }
199
+ decExpected, err := decimal.NewFromString(testcase.numString)
200
+ if err != nil {
201
+ t.Fatalf("Failed to encode string to decimal")
202
+ }
203
+ if !decExpected.Equal(decActual) {
204
+ t.Fatalf("Failed to decode decimal (%s) from BCD (%x) - '%x'", testcase.numString, testcase.bcdBuf, s)
205
+ }
206
+ */
198
207
})
199
208
}
200
209
}
0 commit comments