@@ -64,6 +64,8 @@ TestMathsCatSnippets = class(TTestCase)
6464 procedure TestWeightedHarmonicMean_Double_ExceptDiffSizeArrays ;
6565 procedure TestWeightedHarmonicMean_Double_ExceptNegativeWeights ;
6666 procedure TestWeightedHarmonicMean_Double_ExceptZeroWeights ;
67+ procedure TestLogarithmicMean_ExceptNonPositive ;
68+ procedure TestLogarithmicMean_ExceptZero ;
6769 function EqualArrays (const Left, Right: TBytes): Boolean; overload;
6870 function EqualArrays (const Left, Right: array of Double;
6971 Fudge: Double = 0.0 ): Boolean; overload;
@@ -153,6 +155,7 @@ TestMathsCatSnippets = class(TTestCase)
153155 procedure TestWeightedHarmonicMean_Double ; // required by Integer & Cardinal overloads
154156 procedure TestWeightedHarmonicMean_Cardinal ;
155157 procedure TestWeightedHarmonicMean_Integer ;
158+ procedure TestLogarithmicMean ;
156159 end ;
157160
158161implementation
@@ -1022,6 +1025,40 @@ procedure TestMathsCatSnippets.TestLCD;
10221025 CheckEquals(9 , LCD(-9 , -9 ), ' LCD(-9, -9)' );
10231026end ;
10241027
1028+ procedure TestMathsCatSnippets.TestLogarithmicMean ;
1029+ const
1030+ Fudge = 0.000000001 ;
1031+ // Expected values calculated with Windows Calc
1032+ XA = 42.456 ; EA = XA;
1033+ XB = 42.456 ; YB = 56.847 ; EB = 49.3019407666718697 ;
1034+ XC = 0.000001 ; YC = 0.000002 ; EC = 1.4426950408889634e-6 ;
1035+ XD = 0.000001 ; ED = XD;
1036+ XE = 18374983.0 ; YE = 2768293.9362 ; EE = 8245471.247628288866 ;
1037+ XF = 18.374983 ; YF = 2768293.9362 ; EF = 232184.284293825682 ;
1038+ XG = 0.00002356 ; YG = 2768293.9362 ; EG = 108604.405745470878 ;
1039+ begin
1040+ CheckTrue(SameValue(EA, LogarithmicMean(XA, XA), Fudge), ' A (x,x)' );
1041+ CheckTrue(SameValue(EB, LogarithmicMean(XB, YB), Fudge), ' B (x,y)' );
1042+ CheckTrue(SameValue(EB, LogarithmicMean(YB, XB), Fudge), ' B (y,x)' );
1043+ CheckTrue(SameValue(EC, LogarithmicMean(XC, YC), Fudge), ' C (x,y)' );
1044+ CheckTrue(SameValue(ED, LogarithmicMean(XD, XD), Fudge), ' D (x,x)' );
1045+ CheckTrue(SameValue(EE, LogarithmicMean(XE, YE), Fudge), ' E (x,y)' );
1046+ CheckTrue(SameValue(EF, LogarithmicMean(XF, YF), Fudge), ' F (x,y)' );
1047+ CheckTrue(SameValue(EG, LogarithmicMean(XG, YG), Fudge), ' G (x,y)' );
1048+ CheckException(TestLogarithmicMean_ExceptNonPositive, EArgumentException, ' Not positive exception' );
1049+ CheckException(TestLogarithmicMean_ExceptZero, EArgumentException, ' Zero exception' );
1050+ end ;
1051+
1052+ procedure TestMathsCatSnippets.TestLogarithmicMean_ExceptNonPositive ;
1053+ begin
1054+ LogarithmicMean(-2.4 , 1.0 );
1055+ end ;
1056+
1057+ procedure TestMathsCatSnippets.TestLogarithmicMean_ExceptZero ;
1058+ begin
1059+ LogarithmicMean(2.4 , 0.0 );
1060+ end ;
1061+
10251062procedure TestMathsCatSnippets.TestLSE ;
10261063const
10271064 Fudge = 0.000001 ;
0 commit comments