Added TBigInt.GetMostSignificantBitIndex and tests
This commit is contained in:
@@ -70,6 +70,17 @@ type
|
||||
procedure TestLongNegative;
|
||||
end;
|
||||
|
||||
{ TBigIntMostSignificantBitIndexTestCase }
|
||||
|
||||
TBigIntMostSignificantBitIndexTestCase = class(TTestCase)
|
||||
private
|
||||
procedure Test(const ABinValue: string; const AExpectedIndex: Int64);
|
||||
published
|
||||
procedure TestZero;
|
||||
procedure TestShort;
|
||||
procedure TestLong;
|
||||
end;
|
||||
|
||||
{ TBigIntFromInt64TestCase }
|
||||
|
||||
TBigIntFromInt64TestCase = class(TTestCase)
|
||||
@@ -271,6 +282,37 @@ begin
|
||||
Test('-192648F1305DD04757A24C873F29F60B6184B5', -1);
|
||||
end;
|
||||
|
||||
{ TBigIntMostSignificantBitIndexTestCase }
|
||||
|
||||
procedure TBigIntMostSignificantBitIndexTestCase.Test(const ABinValue: string; const AExpectedIndex: Int64);
|
||||
var
|
||||
a: TBigInt;
|
||||
begin
|
||||
a := TBigInt.FromBinaryString(ABinValue);
|
||||
AssertEquals('BigInt from binary string ''' + ABinValue + ''' did not have its most significant bit at index '''
|
||||
+ IntToStr(AExpectedIndex) + '''.',
|
||||
AExpectedIndex, a.GetMostSignificantBitIndex);
|
||||
end;
|
||||
|
||||
procedure TBigIntMostSignificantBitIndexTestCase.TestZero;
|
||||
begin
|
||||
Test('0', -1);
|
||||
end;
|
||||
|
||||
procedure TBigIntMostSignificantBitIndexTestCase.TestShort;
|
||||
begin
|
||||
Test('1', 0);
|
||||
Test('11111101111001', 13);
|
||||
Test('10010111101100001110110101111000', 31);
|
||||
end;
|
||||
|
||||
procedure TBigIntMostSignificantBitIndexTestCase.TestLong;
|
||||
begin
|
||||
Test('111100010101010100011101010100011', 32);
|
||||
Test('11101001101010111101000101010001010101010101111111001010101010010100101000101011111001000111001001100011', 103);
|
||||
Test('111101100011110110111011010111100000000001010111101110101101101100101010110111101011010101001100', 95);
|
||||
end;
|
||||
|
||||
{ TBigIntFromInt64TestCase }
|
||||
|
||||
procedure TBigIntFromInt64TestCase.Test(const AValue: Int64);
|
||||
@@ -903,6 +945,7 @@ end;
|
||||
initialization
|
||||
|
||||
RegisterTest(TBigIntSignTestCase);
|
||||
RegisterTest(TBigIntMostSignificantBitIndexTestCase);
|
||||
RegisterTest(TBigIntFromInt64TestCase);
|
||||
RegisterTest(TBigIntFromHexTestCase);
|
||||
RegisterTest(TBigIntFromBinTestCase);
|
||||
|
||||
Reference in New Issue
Block a user