Browse Source

Faster trandg.pp.

Rika Ichinose 1 year ago
parent
commit
691dc59a2a
1 changed files with 48 additions and 5 deletions
  1. 48 5
      tests/test/units/math/trandg.pp

+ 48 - 5
tests/test/units/math/trandg.pp

@@ -15,17 +15,36 @@ const
 	StdDev = 1.5;
 	StdDev = 1.5;
 	HistogramMin = 0;
 	HistogramMin = 0;
 	HistogramMax = 10;
 	HistogramMax = 10;
-	NHistogramBuckets = 40;
-	NRows = 12;
+	NHistogramBuckets = 80;
+	NRows = 16;
 {$ifdef SMALL_TEST}
 {$ifdef SMALL_TEST}
 	NSamples = 100 * 1000;
 	NSamples = 100 * 1000;
 {$else SMALL_TEST}
 {$else SMALL_TEST}
-	NSamples = 100 * 1000 * 1000;
+	NSamples = 1 * 1000 * 1000;
 {$endif SMALL_TEST}
 {$endif SMALL_TEST}
+	Perfect: array[0 .. NRows - 1, 0 .. NHistogramBuckets - 1] of char =
+	(
+		'                                     #######                                    ',
+		'                                   ###########                                  ',
+		'                                  #############                                 ',
+		'                                #################                               ',
+		'                               ###################                              ',
+		'                             #######################                            ',
+		'                            #########################                           ',
+		'                           ###########################                          ',
+		'                          #############################                         ',
+		'                        #################################                       ',
+		'                       ###################################                      ',
+		'                     #######################################                    ',
+		'                    #########################################                   ',
+		'                 ###############################################                ',
+		'              #####################################################             ',
+		'         ###############################################################        '
+	);
 var
 var
 	hist: array of uint32;
 	hist: array of uint32;
 	iSample, nOutOfRange, maxInBucket: uint32;
 	iSample, nOutOfRange, maxInBucket: uint32;
-	iHist, y: SizeInt;
+	iHist, y, imperfections: SizeInt;
 	row, msg, newMsg: string;
 	row, msg, newMsg: string;
 	time: double;
 	time: double;
 begin
 begin
@@ -59,6 +78,7 @@ begin
 	time := (Now - time) * SecsPerDay;
 	time := (Now - time) * SecsPerDay;
 	write(stderr, #13, StringOfChar(' ', length(msg)), #13);
 	write(stderr, #13, StringOfChar(' ', length(msg)), #13);
 
 
+	imperfections := 0;
 	SetLength(row, NHistogramBuckets);
 	SetLength(row, NHistogramBuckets);
 	for y := 0 to NRows - 1 do
 	for y := 0 to NRows - 1 do
 	begin
 	begin
@@ -66,12 +86,35 @@ begin
 			if (y = 0) and (iHist < length(name)) then
 			if (y = 0) and (iHist < length(name)) then
 				pChar(pointer(row))[iHist] := name[iHist]
 				pChar(pointer(row))[iHist] := name[iHist]
 			else
 			else
+			begin
 				pChar(pointer(row))[iHist] := pChar(' #')[ord(hist[iHist] / maxInBucket >= (NRows - y - 0.5) / NRows)];
 				pChar(pointer(row))[iHist] := pChar(' #')[ord(hist[iHist] / maxInBucket >= (NRows - y - 0.5) / NRows)];
+				if row[iHist] <> Perfect[y, iHist] then
+					if (y > 0) and (y + 1 < NRows) and (row[iHist] <> Perfect[y - 1, iHist]) and (row[iHist] <> Perfect[y + 1, iHist])
+{$ifdef SMALL_TEST}
+						and
+						(
+							// Allow 2-storey imperfections for 25 columns in the middle.
+							(abs(iHist - round((Mean - HistogramMin) / (HistogramMax - HistogramMin) * NHistogramBuckets)) > 12) or
+							(y > 1) and (y + 2 < NRows) and (row[iHist] <> Perfect[y - 2, iHist]) and (row[iHist] <> Perfect[y + 2, iHist])
+						)
+{$endif}
+					then
+					begin
+						pChar(pointer(row))[iHist] := '!';
+						imperfections := High(imperfections) div 2;
+					end else
+					begin
+						pChar(pointer(row))[iHist] := '*';
+						imperfections += 1;
+					end;
+			end;
 		writeln(row);
 		writeln(row);
 	end;
 	end;
 	writeln('Out of range: ', nOutOfRange, ' / ', NSamples, ' (', nOutOfRange / nSamples * 100:0:1, '%).', LineEnding,
 	writeln('Out of range: ', nOutOfRange, ' / ', NSamples, ' (', nOutOfRange / nSamples * 100:0:1, '%).', LineEnding,
 		'Took ', time:0:1, ' s.', LineEnding);
 		'Took ', time:0:1, ' s.', LineEnding);
-	if nOutOfRange / nSamples>0.001 then
+	if nOutOfRange / nSamples>0.0015 then
+	  halt(1);
+	if imperfections > {$ifdef SMALL_TEST} 40 {$else} 16 {$endif} then
 	  halt(1);
 	  halt(1);
 end;
 end;