Added tests for BinomialCoefficients global var

This commit is contained in:
Stefan Müller 2024-11-20 00:05:44 +01:00
parent f61abcb9c3
commit 3008efc4ae
1 changed files with 25 additions and 1 deletions

View File

@ -47,6 +47,15 @@ type
procedure TestRangeError;
end;
{ TBinomialCoefficientsGlobalTestCase }
TBinomialCoefficientsGlobalTestCase = class(TTestCase)
private
procedure AssertEqualsCalculation(const AN, AK, AExpected: Cardinal);
published
procedure TestCombined;
end;
implementation
{ TBinomialCoefficientsTestCase }
@ -131,8 +140,23 @@ begin
AssertException(ERangeError, @RunRangeError);
end;
{ TBinomialCoefficientsGlobalTestCase }
procedure TBinomialCoefficientsGlobalTestCase.AssertEqualsCalculation(const AN, AK, AExpected: Cardinal);
begin
AssertEquals('Unexpected calculation result', AExpected, BinomialCoefficients.Get(AN, AK));
end;
procedure TBinomialCoefficientsGlobalTestCase.TestCombined;
begin
AssertEqualsCalculation(5, 1, 5);
AssertEqualsCalculation(8, 4, 70);
AssertEqualsCalculation(3, 1, 3);
end;
initialization
RegisterTest('Helper', TBinomialCoefficientsTestCase);
RegisterTest('Helper.TBinomialCoefficientCache', TBinomialCoefficientsTestCase);
RegisterTest('Helper.TBinomialCoefficientCache', TBinomialCoefficientsGlobalTestCase);
end.