@@ -86,6 +86,8 @@ TestMathsCatSnippets = class(TTestCase)
8686 procedure TestIsNarcissistic ;
8787 procedure TestLSE ; // required by SoftMax
8888 procedure TestSoftMax ;
89+ procedure TestMedian_Integer ;
90+ procedure TestMedian_Double ;
8991 end ;
9092
9193implementation
@@ -881,6 +883,38 @@ procedure TestMathsCatSnippets.TestMaxOfArray_Single;
881883 Check(SameValue(N, MaxOfArray(A)), ' Test 5' );
882884end ;
883885
886+ procedure TestMathsCatSnippets.TestMedian_Double ;
887+ const
888+ Fudge = 0.000001 ;
889+ A1: array [1 ..1 ] of Double = (436.57 );
890+ A2: array [1 ..2 ] of Double = (-123.45 , 170.05 );
891+ A5: array [1 ..5 ] of Double = (1.234 , 4256.12345 , 7000000000.0 , PI, 0.000006758493 );
892+ A6: array [1 ..6 ] of Double = (4883.937382 , 37473.0 , 235.00001 , -99.9282 , 42.32654 , 56.986382 );
893+ A7: array [1 ..7 ] of Double = (938298.0837 , 729837.3627 , 80001.34 , 79876.46372 , 67012.1234 , 38983.12 , 3500.93937 );
894+ begin
895+ CheckTrue(SameValue(436.57 , Median(A1), Fudge), ' #1' );
896+ CheckTrue(SameValue(23.3 , Median(A2), Fudge), ' #2' );
897+ CheckTrue(SameValue(PI, Median(A5), Fudge), ' #5' );
898+ CheckTrue(SameValue(145.993196 , Median(A6), Fudge), ' #6' );
899+ CheckTrue(SameValue(79876.46372 , Median(A7), Fudge), ' #7' );
900+ end ;
901+
902+ procedure TestMathsCatSnippets.TestMedian_Integer ;
903+ const
904+ A1: array [1 ..1 ] of Integer = (4 );
905+ A2: array [1 ..2 ] of Integer = (-6 , 1 );
906+ A5: array [1 ..5 ] of Integer = (1 , 3 , 5 , 7 , 9 );
907+ A6: array [1 ..6 ] of Integer = (4883 , 37473 , 235 , -99 , 42 , 56 );
908+ A7: array [1 ..7 ] of Integer = (77 , 66 , 55 , 44 , 33 , 22 , 11 );
909+ begin
910+ CheckTrue(SameValue(4.0 , Median(A1)), ' #1' );
911+ CheckTrue(SameValue(-2.5 , Median(A2)), ' #2' );
912+ CheckTrue(SameValue(5.0 , Median(A5)), ' #5' );
913+ CheckTrue(SameValue(145.5 , Median(A6)), ' #6' );
914+ CheckTrue(SameValue(44.0 , Median(A7)), ' #7' );
915+
916+ end ;
917+
884918procedure TestMathsCatSnippets.TestMid_Double ;
885919var
886920 A, B, C, D, E: Double;
0 commit comments