@@ -86,6 +86,8 @@ TestMathsCatSnippets = class(TTestCase)
8686 procedure TestModeCount_ExceptSingleElementArray ;
8787 procedure TestRMS_Double_ExceptEmptyArray ;
8888 procedure TestRMS_Integer_ExceptEmptyArray ;
89+ procedure TestTSS_Double_ExceptEmptyArray ;
90+ procedure TestTSS_Integer_ExceptEmptyArray ;
8991 function EqualArrays (const Left, Right: TBytes): Boolean; overload;
9092 function EqualArrays (const Left, Right: array of Integer): Boolean;
9193 overload;
@@ -191,6 +193,8 @@ TestMathsCatSnippets = class(TTestCase)
191193 procedure TestModeCount ;
192194 procedure TestRMS_Double ;
193195 procedure TestRMS_Integer ;
196+ procedure TestTSS_Double ;
197+ procedure TestTSS_Integer ;
194198 end ;
195199
196200implementation
@@ -2791,6 +2795,76 @@ procedure TestMathsCatSnippets.TestSumOfReciprocals_Integer_ExceptNonPositive;
27912795 SumOfReciprocals(A);
27922796end ;
27932797
2798+ procedure TestMathsCatSnippets.TestTSS_Double ;
2799+ const
2800+ // Expected results calculated using
2801+ // https://www.socscistatistics.com/tests/sumofsquares/default.aspx
2802+ Fudge = 0.00001 ;
2803+ A: array [1 ..4 ] of Double = (49.7 , -89.3 , 9.36 , 10.0 );
2804+ EA = 10529.7752 ;
2805+ B: array [1 ..1 ] of Double = (7483.84 );
2806+ EB = 0.0 ;
2807+ C: array [1 ..3 ] of Double = (7483.84 , 7483.84 , 7483.84 );
2808+ EC = 0.0 ;
2809+ D: array [1 ..3 ] of Double = (-7483.84 , -7483.84 , -7483.84 );
2810+ ED = 0.0 ;
2811+ E: array [1 ..3 ] of Double = (-7483.84 , 7483.84 , -7483.84 );
2812+ EE = 149354296.38827 ;
2813+ F: array [1 ..6 ] of Double = (-42.0 , 42.0 , -56.0 , 56.0 , -4256.42 , 4256.42 );
2814+ EF = 36244022.4328 ;
2815+ begin
2816+ CheckEquals(EA, TSS(A), Fudge, ' A' );
2817+ CheckEquals(EB, TSS(B), Fudge, ' B' );
2818+ CheckEquals(EC, TSS(C), Fudge, ' C' );
2819+ CheckEquals(ED, TSS(D), Fudge, ' D' );
2820+ CheckEquals(EE, TSS(E), Fudge, ' E' );
2821+ CheckEquals(EF, TSS(F), Fudge, ' F' );
2822+ CheckException(TestTSS_Double_ExceptEmptyArray, EArgumentException, ' Empty array' );
2823+ end ;
2824+
2825+ procedure TestMathsCatSnippets.TestTSS_Double_ExceptEmptyArray ;
2826+ var
2827+ A: array of Double;
2828+ begin
2829+ SetLength(A, 0 );
2830+ TSS(A);
2831+ end ;
2832+
2833+ procedure TestMathsCatSnippets.TestTSS_Integer ;
2834+ const
2835+ // Expected results calculated using
2836+ // https://www.socscistatistics.com/tests/sumofsquares/default.aspx
2837+ Fudge = 0.00001 ;
2838+ A: array [1 ..4 ] of Integer = (50 , -89 , 9 , 10 );
2839+ EA = 10502.0 ;
2840+ B: array [1 ..1 ] of Integer = (7484 );
2841+ EB = 0.0 ;
2842+ C: array [1 ..3 ] of Integer = (7484 , 7484 , 7484 );
2843+ EC = 0.0 ;
2844+ D: array [1 ..3 ] of Integer = (-7484 , -7484 , -7484 );
2845+ ED = 0.0 ;
2846+ E: array [1 ..3 ] of Integer = (-7484 , 7484 , -7484 );
2847+ EE = 149360682.66667 ;
2848+ F: array [1 ..6 ] of Integer = (-42 , 42 , -56 , 56 , -4256 , 4256 );
2849+ EF = 36236872.0 ;
2850+ begin
2851+ CheckEquals(EA, TSS(A), Fudge, ' A' );
2852+ CheckEquals(EB, TSS(B), Fudge, ' B' );
2853+ CheckEquals(EC, TSS(C), Fudge, ' C' );
2854+ CheckEquals(ED, TSS(D), Fudge, ' D' );
2855+ CheckEquals(EE, TSS(E), Fudge, ' E' );
2856+ CheckEquals(EF, TSS(F), Fudge, ' F' );
2857+ CheckException(TestTSS_Integer_ExceptEmptyArray, EArgumentException, ' Empty array' );
2858+ end ;
2859+
2860+ procedure TestMathsCatSnippets.TestTSS_Integer_ExceptEmptyArray ;
2861+ var
2862+ A: array of Integer;
2863+ begin
2864+ SetLength(A, 0 );
2865+ TSS(A);
2866+ end ;
2867+
27942868procedure TestMathsCatSnippets.TestWeightedArithmeticMean_Cardinal ;
27952869const
27962870 A: array [1 ..3 ] of Cardinal = (12 , 6 , 3 );
0 commit comments