From fa5616f3cca597fb4398f7d9ab5ebf1bc904fad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Sat, 25 May 2024 02:35:55 +0200 Subject: [PATCH] Fixed initializer of zero polynomial --- UPolynomial.pas | 4 ++++ tests/UPolynomialTestCases.pas | 16 +++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/UPolynomial.pas b/UPolynomial.pas index 035cb09..5d33937 100644 --- a/UPolynomial.pas +++ b/UPolynomial.pas @@ -256,6 +256,10 @@ begin SetLength(Result.FCoefficients, high + 1); for i := 0 to high do Result.FCoefficients[i] := ACoefficients[i]; + end + else begin + SetLength(Result.FCoefficients, 1); + Result.FCoefficients[0] := TBigInt.Zero; end; end; diff --git a/tests/UPolynomialTestCases.pas b/tests/UPolynomialTestCases.pas index c0e9e91..e260f97 100644 --- a/tests/UPolynomialTestCases.pas +++ b/tests/UPolynomialTestCases.pas @@ -33,9 +33,7 @@ type procedure TestCreateWithDegree(const ACoefficients: array of TBigInt; const ADegree: Integer); published procedure TestCreate; - procedure TestCreateDegreeOne; procedure TestCreateDegreeZero; - procedure TestCreateDegreeZeroTrim; procedure TestEqual; procedure TestUnequalSameLength; procedure TestUnequalDifferentLength; @@ -66,19 +64,11 @@ begin TestCreateWithDegree([992123, 7, 20, 4550022], 3); end; -procedure TBigIntPolynomialTestCase.TestCreateDegreeOne; -begin - TestCreateWithDegree([4007], 0); -end; - procedure TBigIntPolynomialTestCase.TestCreateDegreeZero; begin - TestCreateWithDegree([], -1); -end; - -procedure TBigIntPolynomialTestCase.TestCreateDegreeZeroTrim; -begin - TestCreateWithDegree([0], -1); + TestCreateWithDegree([4007], 0); + TestCreateWithDegree([], 0); + TestCreateWithDegree([0], 0); end; procedure TBigIntPolynomialTestCase.TestEqual;