@@ -143,28 +143,30 @@ var decimalBCD = []struct {
143
143
bcdBuf []byte
144
144
numString string
145
145
}{
146
- {[]byte {0x02 , 0x01 , 0x23 , 0x4b }, "-12.34" },
147
- //{[]byte{0x0, 0xa}, "0"}, // WRONG 00000a
148
- //{[]byte{0x0, 0xb}, "-0"}, // WRONG 00000b
149
- {[]byte {0x0 , 0x1a }, "1" }, // WRONG 00010a
150
- //{[]byte{0x0, 0x1b}, "-1"}, // WRONG 00010b
151
- //{[]byte{0x1, 0x1a}, "0.1"}, // WRONG 00010a
152
- //{[]byte{0x1, 0x1b}, "-0.1"}, // WRONG 00010b
153
- //{[]byte{0x25, 0x1a}, "0.0000000000000000000000000000000000001"}, // WRONG 25000000000000000000000000000000000000001a
154
- //{[]byte{0x25, 0x1b}, "-0.0000000000000000000000000000000000001"}, // WRONG 25000000000000000000000000000000000000001b
155
- //{[]byte{0x26, 0x1a}, "0.00000000000000000000000000000000000001"}, // WRONG 2600000000000000000000000000000000000000010a
156
- //{[]byte{0x26, 0x1b}, "-0.00000000000000000000000000000000000001"}, // WRONG 2600000000000000000000000000000000000000010b
157
-
158
- //{[]byte{0x03, 0x01, 0x24, 0x01, 0x0c}, "0.000000000000000000000000000000000010"},
159
- // {[]byte{0xc70b010f0123456789000000000c}, "123.456789000000000"},
160
- // {[]byte{0xc70a010f02718281828459045c}, "2.718281828459045"},
161
- // {[]byte{0xc70a010f02718281828459045d}, "-2.718281828459045"},
162
- // {[]byte{0xc70a010f03141592653589793c}, "3.141592653589793"},
163
- // {[]byte{0xc70a010f03141592653589793d}, "-3.141592653589793"},
164
- // {[]byte{0xc7150100099999999999999999999999999999999999999c}, "99999999999999999999999999999999999999"},
165
- // {[]byte{0xc7150100099999999999999999999999999999999999999d}, "-99999999999999999999999999999999999999"},
166
- // {[]byte{0xc7150113012345678912345678900987654321987654321c}, "1234567891234567890.0987654321987654321"},
167
- // {[]byte{0xc7150113012345678912345678900987654321987654321d}, "-1234567891234567890.0987654321987654321"},
146
+ //{[]byte{0x0, 0x1a}, "1"}, // d501001c
147
+ //{[]byte{0x0, 0x1b}, "-1"}, // d501001d
148
+ //{[]byte{0x1, 0x1a}, "0.1"}, // d501011c
149
+ //{[]byte{0x1, 0x1b}, "-0.1"}, // d501011d
150
+ //{[]byte{0x25, 0x1a}, "0.0000000000000000000000000000000000001"}, // d501251c
151
+ //{[]byte{0x25, 0x1b}, "-0.0000000000000000000000000000000000001"}, // d501251d
152
+ //{[]byte{0x26, 0x1a}, "0.00000000000000000000000000000000000001"}, // d501261c
153
+ //{[]byte{0x26, 0x1b}, "-0.00000000000000000000000000000000000001"}, // d501261d
154
+ //{[]byte{0x03, 0x01, 0x24, 0x01, 0x0c}, "0.000000000000000000000000000000000010"}, // c7030124010c
155
+ //{[]byte{0x00, 0x09, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9c}, "99999999999999999999999999999999999999"}, // c7150100099999999999999999999999999999999999999c
156
+ //{[]byte{0x00, 0x09, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x9d}, "-99999999999999999999999999999999999999"}, // c7150100099999999999999999999999999999999999999d
157
+
158
+ {[]byte {0x02 , 0x01 , 0x23 , 0x4b }, "-12.34" }, // d6010201234d
159
+ {[]byte {0x02 , 0x01 , 0x23 , 0x4a }, "12.34" }, // d6010201234c
160
+ {[]byte {0x01 , 0x01 , 0x4a }, "1.4" }, // c7030101014c
161
+ {[]byte {0x0 , 0xa }, "0" }, // d501000c
162
+ {[]byte {0x0 , 0xb }, "-0" }, // d501000d
163
+ {[]byte {0x0f , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0x00 , 0x00 , 0x00 , 0x00 , 0x0a }, "123.456789000000000" }, // c70b010f0123456789000000000c
164
+ {[]byte {0x0f , 0x02 , 0x71 , 0x82 , 0x81 , 0x82 , 0x84 , 0x59 , 0x04 , 0x5a }, "2.718281828459045" }, // c70a010f02718281828459045c
165
+ {[]byte {0x0f , 0x02 , 0x71 , 0x82 , 0x81 , 0x82 , 0x84 , 0x59 , 0x04 , 0x5b }, "-2.718281828459045" }, // c70a010f02718281828459045d
166
+ {[]byte {0x0f , 0x03 , 0x14 , 0x15 , 0x92 , 0x65 , 0x35 , 0x89 , 0x79 , 0x3a }, "3.141592653589793" }, // c70a010f03141592653589793c
167
+ {[]byte {0x0f , 0x03 , 0x14 , 0x15 , 0x92 , 0x65 , 0x35 , 0x89 , 0x79 , 0x3b }, "-3.141592653589793" }, // c70a010f03141592653589793d
168
+ {[]byte {0x13 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0x12 , 0x34 , 0x56 , 0x78 , 0x90 , 0x09 , 0x87 , 0x65 , 0x43 , 0x21 , 0x98 , 0x76 , 0x54 , 0x32 , 0x1a }, "1234567891234567890.0987654321987654321" }, // c7150113012345678912345678900987654321987654321c
169
+ {[]byte {0x13 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0x12 , 0x34 , 0x56 , 0x78 , 0x90 , 0x09 , 0x87 , 0x65 , 0x43 , 0x21 , 0x98 , 0x76 , 0x54 , 0x32 , 0x1b }, "-1234567891234567890.0987654321987654321" }, // c7150113012345678912345678900987654321987654321d
168
170
}
169
171
170
172
func TestMPEncodeStringToBCD (t * testing.T ) {
@@ -176,7 +178,9 @@ func TestMPEncodeStringToBCD(t *testing.T) {
176
178
177
179
}
178
180
if reflect .DeepEqual (buf , testcase .bcdBuf ) != true {
179
- t .Fatalf ("Failed to encode string with decimal '%s' to BCD (actual: '%x', expected '%x')" , testcase .numString , buf , testcase .bcdBuf )
181
+ fmt .Printf ("Actual: '%x'\n " , buf )
182
+ fmt .Printf ("Expected: '%x'\n " , testcase .bcdBuf )
183
+ t .Fatalf ("Failed to encode string with decimal '%s' to BCD" , testcase .numString )
180
184
}
181
185
})
182
186
}
@@ -190,20 +194,18 @@ func TestMPDecodeStringFromBCD(t *testing.T) {
190
194
t .Fatalf ("Failed to decode BCD ('%x') to string with decimal (actual: '%s', expected '%s')" , testcase .bcdBuf , s , testcase .numString )
191
195
}
192
196
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
- */
197
+ descStr := strings .Join (s , "" )
198
+ decActual , err := decimal .NewFromString ()
199
+ if err != nil {
200
+ t .Fatalf ("Failed to encode string ('%s') to decimal" , decStr )
201
+ }
202
+ decExpected , err := decimal .NewFromString (testcase .numString )
203
+ if err != nil {
204
+ t .Fatalf ("Failed to encode string to decimal" )
205
+ }
206
+ if ! decExpected .Equal (decActual ) {
207
+ t .Fatalf ("Failed to decode decimal (%s) from BCD (%x) - '%x'" , testcase .numString , testcase .bcdBuf , s )
208
+ }
207
209
})
208
210
}
209
211
}
0 commit comments