From 3008efc4ae6a8ea2773554a717ae5dea8665975a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 20 Nov 2024 00:05:44 +0100 Subject: [PATCH] Added tests for BinomialCoefficients global var --- tests/UBinomialCoefficientsTestCases.pas | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/UBinomialCoefficientsTestCases.pas b/tests/UBinomialCoefficientsTestCases.pas index 4de87b4..76d24a3 100644 --- a/tests/UBinomialCoefficientsTestCases.pas +++ b/tests/UBinomialCoefficientsTestCases.pas @@ -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.