Skip to content

Commit 7076cde

Browse files
committed
[MERGE #5662 @duongnhn] add nativetest for FInitFromDigits method of unsigned BigInt class
Merge pull request #5662 from duongnhn:user/duongn/nativetest-unsigned-bigint method: initialize an unsigned BigInt from char of decimal digits.
2 parents 6426b60 + 15ba613 commit 7076cde

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

bin/NativeTests/BigIntTest.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

lib/Common/DataStructures/BigInt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)