@@ -84,6 +84,8 @@ TestMathsCatSnippets = class(TTestCase)
8484 procedure TestHasMode_ExceptSingleElementArray ;
8585 procedure TestModeCount_ExceptEmptyArray ;
8686 procedure TestModeCount_ExceptSingleElementArray ;
87+ procedure TestRMS_Double_ExceptEmptyArray ;
88+ procedure TestRMS_Integer_ExceptEmptyArray ;
8789 function EqualArrays (const Left, Right: TBytes): Boolean; overload;
8890 function EqualArrays (const Left, Right: array of Integer): Boolean;
8991 overload;
@@ -187,6 +189,8 @@ TestMathsCatSnippets = class(TTestCase)
187189 procedure TestModeAlt ;
188190 procedure TestHasMode ;
189191 procedure TestModeCount ;
192+ procedure TestRMS_Double ;
193+ procedure TestRMS_Integer ;
190194 end ;
191195
192196implementation
@@ -2418,6 +2422,58 @@ procedure TestMathsCatSnippets.TestResizeRect_B;
24182422 CheckEquals(-4 , RectHeight(R), ' 3: RectHeight' );
24192423end ;
24202424
2425+ procedure TestMathsCatSnippets.TestRMS_Double ;
2426+ const
2427+ Fudge = 0.0001 ;
2428+ A: array [1 ..4 ] of Double = (23.45 , 35.786 , 87326.948 , 13 );
2429+ B: array [1 ..8 ] of Double = (-19.0 , 27.890 , -42.83729 , 56.73829 , 100.0 , -100.0 , 0.0 , 666.6 );
2430+ C: array [1 ..3 ] of Double = (0.0 , 0.0 , 0.0 );
2431+ D: array [1 ..1 ] of Double = (2345.67889 );
2432+ E: array [1 ..2 ] of Double = (-999.99 , +999.99 );
2433+ begin
2434+ // Some expected results from https://miniwebtool.com/root-mean-square-calculator/
2435+ CheckEquals(43663.47973 , RMS(A), Fudge, ' A' );
2436+ CheckEquals(242.5254314 , RMS(B), Fudge, ' B' );
2437+ CheckEquals(0.0 , RMS(C), Fudge, ' C' );
2438+ CheckEquals(2345.67889 , RMS(D), Fudge, ' D' );
2439+ CheckEquals(999.99 , RMS(E), Fudge, ' E' );
2440+ CheckException(TestRMS_Double_ExceptEmptyArray, EArgumentException, ' Empty array' );
2441+ end ;
2442+
2443+ procedure TestMathsCatSnippets.TestRMS_Double_ExceptEmptyArray ;
2444+ var
2445+ A: array of Double;
2446+ begin
2447+ SetLength(A, 0 );
2448+ RMS(A);
2449+ end ;
2450+
2451+ procedure TestMathsCatSnippets.TestRMS_Integer ;
2452+ const
2453+ Fudge = 0.0001 ;
2454+ A: array [1 ..4 ] of Integer = (23 , 36 , 87327 , 13 );
2455+ B: array [1 ..8 ] of Integer = (-19 , 28 , -43 , 57 , 100 , -100 , 0 , 666 );
2456+ C: array [1 ..3 ] of Integer = (0 , 0 , 0 );
2457+ D: array [1 ..1 ] of Integer = (2346 );
2458+ E: array [1 ..2 ] of Integer = (-999 , +999 );
2459+ begin
2460+ // Some expected results from https://miniwebtool.com/root-mean-square-calculator/
2461+ CheckEquals(43663.505708428864 , RMS(A), Fudge, ' A' );
2462+ CheckEquals(242.3321584 , RMS(B), Fudge, ' B' );
2463+ CheckEquals(0.0 , RMS(C), Fudge, ' C' );
2464+ CheckEquals(2346.0 , RMS(D), Fudge, ' D' );
2465+ CheckEquals(999.0 , RMS(E), Fudge, ' E' );
2466+ CheckException(TestRMS_Integer_ExceptEmptyArray, EArgumentException, ' Empty array' );
2467+ end ;
2468+
2469+ procedure TestMathsCatSnippets.TestRMS_Integer_ExceptEmptyArray ;
2470+ var
2471+ A: array of Integer;
2472+ begin
2473+ SetLength(A, 0 );
2474+ RMS(A);
2475+ end ;
2476+
24212477procedure TestMathsCatSnippets.TestSoftMax ;
24222478
24232479 function ArraysEqual (const Left, Right: array of Double): Boolean;
0 commit comments