@@ -21,6 +21,8 @@ TestMathsCatSnippets = class(TTestCase)
2121 procedure TestDigitSumBase_Except ;
2222 procedure TestDigitsOf_ArgExcept ;
2323 procedure TestPowNZN_EOverflow ;
24+ procedure TestDigitPowerSum_EOverflow ;
25+ procedure TestDigitPowerSum_EArgumentException ;
2426 function EqualArrays (const Left, Right: TBytes): Boolean;
2527 function ReverseArray (const A: TBytes): TBytes;
2628 published
@@ -52,7 +54,7 @@ TestMathsCatSnippets = class(TTestCase)
5254 procedure TestMaxOfArray_Single ;
5355 procedure TestMaxOfArray_Double ;
5456 procedure TestMaxOfArray_Extended ;
55- procedure TestPowNZN ;
57+ procedure TestPowNZN ; // required by DigitPowerSum
5658 procedure TestPowNZZ ;
5759 procedure TestPowN ;
5860 procedure TestArraySum_Single ;
@@ -78,6 +80,7 @@ TestMathsCatSnippets = class(TTestCase)
7880 procedure TestDigitCountBase ;
7981 procedure TestDigitSumBase ;
8082 procedure TestDigitsOf ;
83+ procedure TestDigitPowerSum ;
8184 end ;
8285
8386implementation
@@ -417,6 +420,33 @@ procedure TestMathsCatSnippets.TestDigitCountR;
417420 CheckEquals(5 , DigitCountR(-12345 ), ' DigitCountR(-12345)' );
418421end ;
419422
423+ procedure TestMathsCatSnippets.TestDigitPowerSum ;
424+ begin
425+ CheckEquals(35 , DigitPowerSum(135 , 10 , 2 ), ' #1' );
426+ CheckEquals(0 , DigitPowerSum(0 , 8 , 5 ), ' #2' );
427+ CheckEquals(3 , DigitPowerSum(510 , 10 , 0 ), ' #3' );
428+ CheckEquals(30 , DigitPowerSum($FF, 16 , 1 ), ' #4' );
429+ CheckEquals(12613 , DigitPowerSum(1685237180 , 10 , 4 ), ' #5' );
430+ CheckEquals(77907 , DigitPowerSum(1685237180 { 6472ADBC hex} , 16 , 4 ), ' #6' );
431+ CheckEquals(6740 , DigitPowerSum(1685237180 { 14434526674 oct} , 8 , 4 ), ' #7' );
432+ CheckEquals(-6740 , DigitPowerSum(-1685237180 { 14434526674 oct} , 8 , 4 ), ' #8' );
433+ CheckEquals(17 , DigitPowerSum(1685237180 { 1100100011100101010110110111100 bin} , 2 , 4 ), ' #9' );
434+ CheckEquals(2409140909625644483 , DigitPowerSum(MaxInt { C87E66B7 base 15} , 15 , 16 ), ' #10' );
435+ CheckException(TestDigitPowerSum_EArgumentException, EArgumentException, ' EArgumentException' );
436+ CheckException(TestDigitPowerSum_EOverflow, EOverflow, ' EOverflow' );
437+ // EOverflow can also be raised by PowNZN, not tested here
438+ end ;
439+
440+ procedure TestMathsCatSnippets.TestDigitPowerSum_EArgumentException ;
441+ begin
442+ DigitPowerSum(42 , 1 , 2 ); // Base = 1 => EArgumentException
443+ end ;
444+
445+ procedure TestMathsCatSnippets.TestDigitPowerSum_EOverflow ;
446+ begin
447+ DigitPowerSum(88888888 , 10 , 20 ); // overflows High(Int64) by 1
448+ end ;
449+
420450procedure TestMathsCatSnippets.TestDigitsOf ;
421451var
422452 E: TBytes;
0 commit comments