File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
lib/Common/DataStructures Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -222,4 +222,54 @@ namespace BigIntTest
222
222
{
223
223
}
224
224
}
225
+
226
+ TEST_CASE (" Init_From_Char_Of_Digits" , " [BigIntTest]" )
227
+ {
228
+ BigInt biDec;
229
+ char *charDigit;
230
+ bool result;
231
+ int charDigitLength;
232
+
233
+ SECTION (" 2**32-1 should have length = 1" )
234
+ {
235
+ charDigit = " 4294967295" ;
236
+ charDigitLength = 10 ;
237
+ result = biDec.FInitFromDigits (charDigit, charDigitLength, &charDigitLength);
238
+ REQUIRE (result);
239
+ int length = biDec.Clu ();
240
+ CHECK (length == 1 );
241
+ uint32 digit = biDec.Lu (0 );
242
+ CHECK (digit == 4294967295 );
243
+ }
244
+
245
+ SECTION (" 2**32+2 should have length = 2" )
246
+ {
247
+ charDigit = " 4294967298" ;
248
+ charDigitLength = 10 ;
249
+ result = biDec.FInitFromDigits (charDigit, charDigitLength, &charDigitLength);
250
+ REQUIRE (result);
251
+ int length = biDec.Clu ();
252
+ CHECK (length == 2 );
253
+ uint32 digit = biDec.Lu (0 );
254
+ CHECK (digit == 2 );
255
+ digit = biDec.Lu (1 );
256
+ CHECK (digit == 1 );
257
+ }
258
+
259
+ SECTION (" 2**64 should have length = 3" )
260
+ {
261
+ charDigit = " 18446744073709551616" ;
262
+ charDigitLength = 20 ;
263
+ result = biDec.FInitFromDigits (charDigit, charDigitLength, &charDigitLength);
264
+ REQUIRE (result);
265
+ int length = biDec.Clu ();
266
+ CHECK (length == 3 );
267
+ uint32 digit = biDec.Lu (0 );
268
+ CHECK (digit == 0 );
269
+ digit = biDec.Lu (1 );
270
+ CHECK (digit == 0 );
271
+ digit = biDec.Lu (2 );
272
+ CHECK (digit == 1 );
273
+ }
274
+ }
225
275
}
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ namespace Js
40
40
bool FInitFromRglu (uint32 *prglu, int32 clu); // init from array and length
41
41
bool FInitFromBigint (BigInt *pbiSrc);
42
42
template <typename EncodedChar>
43
- bool FInitFromDigits (const EncodedChar *prgch, int32 cch, int32 *pcchDec);
43
+ bool FInitFromDigits (const EncodedChar *prgch, int32 cch, int32 *pcchDec); // init from char of digits
44
44
bool FMulAdd (uint32 luMul, uint32 luAdd);
45
45
bool FMulPow5 (int32 c5);
46
46
bool FShiftLeft (int32 cbit);
You can’t perform that action at this time.
0 commit comments