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
222222 {
223223 }
224224 }
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+ }
225275}
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ namespace Js
4040 bool FInitFromRglu (uint32 *prglu, int32 clu); // init from array and length
4141 bool FInitFromBigint (BigInt *pbiSrc);
4242 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
4444 bool FMulAdd (uint32 luMul, uint32 luAdd);
4545 bool FMulPow5 (int32 c5);
4646 bool FShiftLeft (int32 cbit);
You can’t perform that action at this time.
0 commit comments