Added TBigIntPolynomial methods needed for bisection algorithm
This commit is contained in:
@@ -40,6 +40,13 @@ type
|
||||
procedure TestUnequalSameLength;
|
||||
procedure TestUnequalDifferentLength;
|
||||
procedure TestTrimLeadingZeros;
|
||||
procedure TestCalcValueAt;
|
||||
procedure TestSignVariations;
|
||||
procedure TestScaleByPowerOfTwo;
|
||||
procedure TestScaleVariable;
|
||||
procedure TestTranslateVariableByOne;
|
||||
procedure TestRevertOrderOfCoefficients;
|
||||
procedure TestDivideByVariable;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@@ -110,6 +117,69 @@ begin
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestCalcValueAt;
|
||||
var
|
||||
a: TBigIntPolynomial;
|
||||
exp: TBigInt;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([80, 892477222, 0, 921556, 7303]);
|
||||
exp:= TBigInt.FromInt64(16867124285);
|
||||
AssertTrue('Polynomial evaluation unexpected.', a.CalcValueAt(15) = exp);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestSignVariations;
|
||||
var
|
||||
a: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([-10, 15, 0, 10, -20, -15, 0, 0, 5, 10, -10]);
|
||||
AssertEquals(4, a.CalcSignVariations);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestScaleByPowerOfTwo;
|
||||
var
|
||||
a, b: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([10, 7, 5, 1034]).ScaleByPowerOfTwo(7);
|
||||
b := TBigIntPolynomial.Create([128 * 10, 128 * 7, 128 * 5, 128 * 1034]);
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestScaleVariable;
|
||||
var
|
||||
a, b: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([10, 7, 5, 1034]).ScaleVariable(TBigInt.FromInt64(10));
|
||||
b := TBigIntPolynomial.Create([10, 70, 500, 1034000]);
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestTranslateVariableByOne;
|
||||
var
|
||||
a, b: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([10, 7, 5, 1034]).TranslateVariableByOne;
|
||||
b := TBigIntPolynomial.Create([1056, 3119, 3107, 1034]);
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestRevertOrderOfCoefficients;
|
||||
var
|
||||
a, b: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([0, 10, 7, 5, 1034]).RevertOrderOfCoefficients;
|
||||
b := TBigIntPolynomial.Create([1034, 5, 7, 10]);
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
procedure TBigIntPolynomialTestCase.TestDivideByVariable;
|
||||
var
|
||||
a, b: TBigIntPolynomial;
|
||||
begin
|
||||
a := TBigIntPolynomial.Create([0, 10, 7, 5, 1034]).DivideByVariable;
|
||||
b := TBigIntPolynomial.Create([10, 7, 5, 1034]);
|
||||
AssertTrue('Polynomials are not equal.', a = b);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterTest(TBigIntPolynomialTestCase);
|
||||
|
||||
Reference in New Issue
Block a user