Skip to content

Commit

Permalink
[MERGE #5662 @duongnhn] add nativetest for FInitFromDigits method of …
Browse files Browse the repository at this point in the history
…unsigned BigInt class

Merge pull request #5662 from duongnhn:user/duongn/nativetest-unsigned-bigint

method: initialize an unsigned BigInt from char of decimal digits.
  • Loading branch information
duongnhn committed Sep 5, 2018
2 parents 6426b60 + 15ba613 commit 7076cde
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions bin/NativeTests/BigIntTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,54 @@ namespace BigIntTest
{
}
}

TEST_CASE("Init_From_Char_Of_Digits", "[BigIntTest]")
{
BigInt biDec;
char *charDigit;
bool result;
int charDigitLength;

SECTION("2**32-1 should have length = 1")
{
charDigit = "4294967295";
charDigitLength = 10;
result = biDec.FInitFromDigits(charDigit, charDigitLength, &charDigitLength);
REQUIRE(result);
int length = biDec.Clu();
CHECK(length == 1);
uint32 digit = biDec.Lu(0);
CHECK(digit == 4294967295);
}

SECTION("2**32+2 should have length = 2")
{
charDigit = "4294967298";
charDigitLength = 10;
result = biDec.FInitFromDigits(charDigit, charDigitLength, &charDigitLength);
REQUIRE(result);
int length = biDec.Clu();
CHECK(length == 2);
uint32 digit = biDec.Lu(0);
CHECK(digit == 2);
digit = biDec.Lu(1);
CHECK(digit == 1);
}

SECTION("2**64 should have length = 3")
{
charDigit = "18446744073709551616";
charDigitLength = 20;
result = biDec.FInitFromDigits(charDigit, charDigitLength, &charDigitLength);
REQUIRE(result);
int length = biDec.Clu();
CHECK(length == 3);
uint32 digit = biDec.Lu(0);
CHECK(digit == 0);
digit = biDec.Lu(1);
CHECK(digit == 0);
digit = biDec.Lu(2);
CHECK(digit == 1);
}
}
}
2 changes: 1 addition & 1 deletion lib/Common/DataStructures/BigInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Js
bool FInitFromRglu(uint32 *prglu, int32 clu); // init from array and length
bool FInitFromBigint(BigInt *pbiSrc);
template <typename EncodedChar>
bool FInitFromDigits(const EncodedChar *prgch, int32 cch, int32 *pcchDec);
bool FInitFromDigits(const EncodedChar *prgch, int32 cch, int32 *pcchDec); // init from char of digits
bool FMulAdd(uint32 luMul, uint32 luAdd);
bool FMulPow5(int32 c5);
bool FShiftLeft(int32 cbit);
Expand Down

0 comments on commit 7076cde

Please sign in to comment.